Do not use #!/bin/sh if you’re not writing bash-only scripts
Actually #!/bin/sh
is for bourne shell compatible scripts. Bash is a superset of the bourne shell, so anything that works in bourne should work in bash as well as in other bourne compatible shells, but not vice versa. Bash specific syntax is often referred to as a "bashism", because it's not compatible with other shells. So you should not use bashisms in scripts that start with #!/bin/sh
.
The trouble is that it is very common for distros to links /bin/sh
to /bin/bash
, and it used to be that bash being called as /bin/sh
would change its behavior so that bashisms would not work, but this doesn't appear to be the case anymore. The result is that people often write what they think are bourne shell scripts but they unintentionally sneak in bashisms... and then when those supposed "bourne shell" scripts get run on a non-bash bourne compatible shell, they fail.
Hah, I was wondering if that was wat you actually meant. The double negation made my head spin a bit.
The weird thing is that
man bash
still says:But if you create a file with a few well known bashisms, and a
#!/bin/sh
shebang, it runs the bashisms just fine.