If a script /path/to/foo
begins with #!/bin/bash
, then executing /path/to/foo arg1 arg2
is equivalent to executing /bin/bash /path/too/foo arg1 arg2
. If the shebang line is #!/bin/bash -ex
, it is equivalent to executing /bin/bash -ex /path/too/foo arg1 arg2
. This feature is managed by the kernel.
Note that you can portably have only one argument on the shebang line: some unices (such as Linux) only accept one argument, so that #!/bin/bash -e -x
would lead to bash receiving the single five-character argument -e -x
(a syntax error) rather than two arguments -e
and -x
.
For the Bourne shell sh
and derived shells such as POSIX sh, bash, ksh, and zsh:
-e
means that if any command fails (which it indicates by returning a nonzero status), the script will terminate immediately.
-x
causes the shell to print an execution trace.
Other programs may understand these options but with different meanings.
Those options are specific to Bash (or other interpreter). They may be the same for other shells (dash and ksh, for example), but they would be different for other interpreters such as AWK and Python. You can use many of the options that the interpreter accepts. The options are interpreter-specific while the shebang is a kernel feature. – Paused until further notice. – 2010-10-04T21:26:13.000