Quantcast
Viewing all articles
Browse latest Browse all 13

Answer by Miten for What does 'set -e' mean in a Bash script?

cat a.sh#! /bin/bash#going forward report subshell or command exit value if errors#set -e(cat b.txt)echo "hi"./a.sh; echo $?cat: b.txt: No such file or directoryhi0

with set -e commented out we see that echo "hi" exit status being reported and hi is printed.

cat a.sh#! /bin/bash#going forward report subshell or command exit value if errorsset -e(cat b.txt)echo "hi"./a.sh; echo $?cat: b.txt: No such file or directory1

Now we see b.txt error being reported instead and no hi printed.

So default behaviour of shell script is to ignore command errors and continue processing and report exit status of last command. If you want to exit on error and report its status we can use -e option.


Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>