Why ((0)) causes the Bash script to exit if the `set -e` directive is present?

This outputs before\n:

#!/usr/bin/env bash
set -e

echo before
((0))
echo after

Removing set -eor changing ((0))to ((1))concludes the program before\nafter\nas expected.

Why does it ((0))cause a termination condition set -e?

+4
source share
2 answers

This will explain:

((0))
echo $?
1

((1))
echo $?
0

Thus, due to the nonzero return status, the evaluation of an arithmetic expression in (( and ))your script exits when used set -e.

As the help setfollowing says:

-e Exit immediately if the command exits with a non-zero status.

+9
source

Line

 set -e

: -e Exit immediately if a command exits with a non-zero status. (.: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html)

((0)) - , 1. script.

+2

Source: https://habr.com/ru/post/1544032/


All Articles