I wrote a bash script under CentOS and it was executed well. On another computer it was wrong. I forgot the shebang at the beginning, but why was it good on my computer? I a
If execve
fails for your script, which it will, /bin/sh
will be used. On one system /bin/sh
may be a POSIX sh
and on another it may be an alias for bash
; your script probably relies on bash
features.
Not having a shebang in the beginning of your script will get it executed in whatever shell is currently running when the script was invoked. If you know for sure that the script will be launched from bash, and not from any other shell (ksh, csh, etc.), there is no need for a shebang, because the same interpreter will be launched.