Apologies if this is a repost. I did search (no luck) before posting this.
"bash -e" will error/fail if there is any error. Doesn't it include the "bash -u" condition? If a parameter is not set won't a command using that parameter fail and caught by "bash -e" ?
Isn't "bash -eu" equal to "bash -e" in that case?
Now what are difference between -bash and bash? Bash started with a dash - as the first character for the command name (argument #0) starts as a login shell. (So does a shell given the -l / --login switch.) That affects the startup files it reads.
The “if –e” and “if –s” are such operators in Bash, used for testing the existence of a file. The difference between the two is that the former only tests the existence of a file, whereas the latter also checks if there are any contents in that file or not.
$ man bash -e file True if file exists. -f file True if file exists and is a regular file. A regular file is something that isn't a directory, symlink, socket, device, etc. Is this answer outdated? -e checks for any type of filesystem object; -f only checks for a regular file.
(more)Loading…. In bash, set +e is basically the default: If you get an error in a bash script, it normally barfs out an error to the system (this is called an exit code) but the script will continue running.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With