Skip to content
Advertisement

Bash command option clarification bash -ex

could you please explain to me what exactly this shell command do? It is quite difficoult to retrive the description of this -ex option.

sh #!/bin/bash -ex

Thanks in advance

Advertisement

Answer

It means you’re invoking new bash shell with -e and -x shell options

See shell options here: https://tldp.org/LDP/abs/html/options.html

-e errexit Abort script at first error, when a command exits with non-zero status (except in until or while loops, if-tests, list constructs)

-x xtrace Similar to -v, but expands commands

since -x is similar to -v:

-v verbose Print each command to stdout before executing it

So it’s actually dropping to next level shell:

$ echo $SHLVL
1
$ sh #!/bin/bash -ex
$ echo $SHLVL
2

in which in this level 2 shell, option -e and -x is activated

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement