This outputs before\n
:
#!/usr/bin/env bash
set -e
echo before
((0))
echo after
Removing set -e
or changing ((0))
to ((1))
makes the program output before\nafter\n
as expected.
Why does ((0))
trigger the set -e
exit condition?
This will explain:
((0))
echo $?
1
((1))
echo $?
0
So it is due to non-zero return status of arithmetic expression evaluation in (( and ))
your script is exiting when set -e
is being used.
As help set
says this:
-e Exit immediately if a command exits with a non-zero status.
Line
set -e
means:
-e Exit immediately if a command exits with a non-zero status.
(see: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html)
((0))
is an expression that evaluates to 1
. That's why the script exits.
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