#!/bin/bash -e :: what is `-e`? other arguments?

9

2

I am a shell script coder that always opt to use shell as top level as part of my belt in creating website apps on the fly and have relied on my bash scripts if I want a project to be implemented FAST.

We all know that we always use #!/bin/bash as a rule of thumb for first line of script, as always. I made it as a habit of closing the script with exit 0 ...every time for any script that comes with #!/bin/bash.

Just recently I came across to this script and was puzzled and tried to find exactly what is this is: #!/bin/bash -e. "What the hell - there is also -e ?!" was my reaction. An insight would be programmaticially appreciated. :)

Faron

Posted 2014-03-15T23:37:31.430

Reputation: 257

For what it's worth, "we all" do not "always use" /bin/bash. You're addressing a world that uses quite a range of script interpreters, from Python and Perl through the Almquist Shell and the Korn Shell to /usr/bin/make -f. – JdeBP – 2014-03-16T15:12:03.253

Heh...I stand corrected on this one, @JdeBP. :) – Faron – 2014-03-27T21:42:39.090

Answers

8

http://www.gnu.org/software/bash/manual/bashref.html#Invoking-Bash
http://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin

-e

Exit immediately if a pipeline [...] returns a non-zero status.

Many details elided, so read that manual.

An example:

#!/bin/bash
set -e   # same as putting -e in the shebang
( exit 42 )
echo "you won't see this:

glenn jackman

Posted 2014-03-15T23:37:31.430

Reputation: 18 546

Gained more insight from that link! Now I saw opportunities to simplify rest of my scripts. Grin-ear-to-ear. Thank you. – Faron – 2014-03-16T01:09:23.083