What is the difference in giving
set -e
set -x
and
set -xe
I'm getting different responses for these. please help me in to get clarified
The set command is a built-in Linux shell command that displays and sets the names and values of shell and Linux environment variables. On Unix-like operating systems, the set command functions within the Bourne shell ( sh ), C shell ( csh ), and Korn shell ( ksh ).
Set –e is used within the Bash to stop execution instantly as a query exits while having a non-zero status. This function is also used when you need to know the error location in the running code.
In Bash, the set command allows you to manage certain flags and characteristics to influence how your bash scripts behave. These controls ensure that your scripts follow the correct path and that Bash's peculiar behavior does not cause difficulties.
set is a command that allows you to enable certain flags in your Bash script to make the script follow certain behaviors and characteristics. If we take a look at the man page, the description is as follows: Set or unset values of shell options and positional parameters.
set -x
Print shell command before execute it. This feature help programmers to track their shell script.
set -e
If the return code of one command is not 0 and the caller does not check it, the shell script will exit. This feature make shell script robust.
set -e
and set -x
often appear at the head of shell script:
set -x
set -e
echo "I am a shell script."
Or use as shell command:
sh -xe shell_script.sh
Reference: http://julio.meroh.net/2010/01/set-e-and-set-x.html
Presumably you are talking about bash. According to its manual, -e
(see section 4.3.1) tells bash to exit under certain conditions (which may apply to your script). If that is the case, "set -xe
" might print more of the trace before exiting than "set -e
" followed by "set -x
".
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