1, SET-E
"Exit immediately if a simple command exits with a Non-zero status."
In the code that appears after "Set-e", once the return value is nonzero, the entire script exits immediately.
2, Set-o Pipefail
"If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a Non-zero status,or Z Ero if all commands in the pipeline exit successfully. This option was disabled by default. "
After this setting is executed, its subsequent code, including the return value of the pipe command, returns a value for the last nonzero command, or returns zero when all the commands inside the pipeline are executed successfully.
As shown in the following example:
When the Set-o Pipifail is not set
#!/bin.bash# There is no a.test,but has b.testcat a.testecho $?cat b.testecho $?cat b.test | echo "HI" echo $?
Cat A.test | echo "HI"
echo $?
The results of the implementation are as follows:
Linux-umlhem:/home/test/shell # sh-x tst.sh+ cat a.testcat:a.test:no such file or directory+ echo 11+ cat b.test----thi S is a test-----+ echo 00+ cat b.test+ echo hihi+ echo 00+ cat a.test+ echo hihicat:a.test:no such file or directory+ EC Ho 00
You can see the cat a.test in execution | echo "HI" returns the result of the rightmost command execution.
Here's an example of setting up Set-o pipeline, as follows:
Set-o Pipefailcat B.test | echo "HI" Echo $?cat a.test | echo "HI" echo $?
The output results are as follows:
+ Set-o pipefail+ cat b.test+ echo hihi+ echo 141141+ cat a.test+ echo hihicat:a.test:no such file or directory+ Echo 1 1
Set-e and Set-o in Linux Pipefail