difference between "bash -eu" . and "bash -e"
No, bash -e
(bash
started with the errexit
shell option set) is not the same as bash -e -u
(bash
started with both errexit
and nounset
set).
Example:
$ bash -e -c 'echo "hello $string"'hello$ echo "$?"0
$ bash -e -u -c 'echo "hello $string"'bash: string: unbound variable$ echo "$?"1
Using an unset variable under only errexit
is not an error, it just expands to an empty string.
Also:
$ bash -u -c 'echo "hello $string"'bash: string: unbound variable$ echo "$?"127
This shows a subtle difference between -e
and -u
. With only -u
, bash
exits with code 127, which translates into a "command not found" error. With both -e
and -u
, bash
exits with a more generic error code of 1.
These things holds true for the POSIX sh
shell as well, although I don't believe that the 127 exit status is explicitly required for the last example.