| There are lots of those footguns in shellscript. One should always try to avoid any shell and rather use python, tcl, perl or powershell. Any criticism one might have about insecure and broken by design languages apply doubly to shell. A short list of possible problems (of course depending on the shell in question): spaces in filenames newlines in filenames nonprintables in filenames empty variables and their expansion ([ x$foo = "xsomething" ]) errors in pipes environment madness /bin/bash ?= /bin/sh Arrays or the lack of it Space separates lists as arrays #!bash vs. #!/bin/bash vs. #!/usr/bin/env bash vs. #!/usr/sfw/bin/bash vs. ... Unwritable and unreadable control structures (if [], case, &&,...) Information leaks via ps and many others... Never use shell except to search for and invoke a sensible language. And anything is more sensible, including C, Perl, brainfuck and Basic. |
There are quite a few pitfalls in shell scripting. You can considerably reduce them by limiting yourself to only being compatible with modern versions of bash and settings things like pipefail, nounset, etc etc.
I do agree that in general a good programming language will be a better option.
> anything is more sensible, including C, Perl, brainfuck and Basic
I do disagree with that however. A 5 line bash script may be 500 lines of C, will take a hundred times longer to write, and may contain memory safety issues (which the bash script at least wouldn't).
I know brainfuck is hyperbolic so I won't argue against that. Something with no filesystem or process forking abilities obviously can't be used for any real task.
I think perl and basic have just as bad syntax as bash though, if not worse. Basic's penchant for "GOTO" is awful, perl's syntax as a whole is just as peculiar as bash's in many places.
I guess my overall point is that bash is usually not a good option compared to modern languages, but it's a darn sight better than you give it credit for. I think it still has its place for 5 or 10 liners that are easy to express and read in bash and don't need any abstractions beyond what coreutils provide.