8 ms·
Why not use Python instead? Shellscript is so... chaotic.
by tormeh 10y ago
Why not use Python instead? Shellscript is so... chaotic.
- chillydawg 10y agocos they run without needing python.
- DonHopkins 10y agoIt's much easier to not need shell scripts, than to not need Python scripts.
- DonHopkins 10y agoI pine for the days of yore when the Unix Philosophy was strong and pure, and every program did one thing well, and only one. Like the way the shell would fork off an "expr" sub-process to parse a mathematical expression to add two numbers, then write the result to a pipe via stdout, then terminate the process, clean up all its resources, and switch context back to the shell, which then read the serialized sum back in from the other end of the pipe, and went about its business, regardless of the fact that the CPU running the shell already had its own built-in "add" instruction in hardware.
- karma_vaccum123 10y ago> I pine for the days of yore when the Unix Philosophy was strong and pure, and every program did one thing well, and only one. Unless you are over fifty years old, you never experienced this. Rob Pike said it best: "Those days are dead and gone and the eulogy was delivered by Perl." Perl being a thing in 1995...
- DonHopkins 10y agoNow "expr" has finally been rewritten as a jQuery plug-in. [1] https://github.com/baphomet-berlin/jQuery-basic-arithmetic-plugin https://github.com/baphomet-berlin/jQuery-basic-arithmetic-p...
- linkregister 10y agoThis is the first coherent refutation of the "do one thing well" ethos I have ever read. Thanks for putting into words what I haven't been able to express myself.
- tom-lord 10y agoShell/batch scripting can often be useful in the devops world, where you have no guarantee that any additional tools (python, ruby, perl, powershell, whatever) wil be available. Shell scripts are guaranteed to be runnable on all machines. Unfortunately the shell "language" sucks, but still...
- kbutler 10y agoSo you're running 'sh' scripts, right? none of that new-fangled bash stuff... Oh, and be very careful of the commands your script invokes! shell scripts have no guarantee of portability (often less than Python, which has a rich standard library available on all platforms).
- CaptSpify 10y ago> Unfortunately the shell "language" sucks, but still... Why do you say that? genuinely curious
- Retra 10y agoShell languages are great at doing interactive programming. Few non-shell languages can match the convenience, flexibility, and expressiveness in that domain. Of course, in any other domain (scripts) they are awful.
- andybak 10y agoPython + Fabric is a lovely devops/sysadmin toolbox.
- aaronbasssett 10y agoStill no Python 3 support though
- mbrock 10y agoHow do you write "foo | bar" in Python?
- IshKebab 10y agoHow often do you actually need to do that. 99% of `foo | bar` command could easily be `foo > a && bar < a` which is pretty trivial to do in Python.
- mbrock 10y agoWell, how do you write that in Python? I'm curious because these simple things that are delightfully easy in bash often turn out to be surprisingly tedious in other languages. Of course, some things are tedious in bash too. But a basic principle of shell scripting is that you call other programs to do the stuff you don't want to do in shell.
- IshKebab 10y agoLike this: http://stackoverflow.com/a/1996540 http://stackoverflow.com/a/1996540 I agree it is tedious, but to be honest, reading and writing to stdin/out isn't something that would commonly need to be done in a robust system. If the world were perfect you would use library functions. I definitely think there is scope for a language that works well as an interactive shell, and as a general purpose language. They have somewhat conflicting constraints but I'm sure we can do better than Bash. Have you seen how [ is implemented?
- mbrock 10y agoNo stdout or stdin for robust systems? I disagree. Yeah, a nicer shell-like language would be cool. I've been thinking about it for a while. Bash is quirky but it gets a lot of stuff right and once you understand it it can be extremely ergonomic and productive. And not depending on language run times other than shell can be really glorious in some situations, too...
- prodigal_erik 10y ago