1.调试脚本
set -e
遇到执行非0时退出脚本;
set-x
打印执行过程;
例1 test1.sh
set -e
set -x
echo //
echo start...
echo //
cat /test.txt
echo end...
#执行结果
yangyijundeMacBook-Pro:~ yangyijun$ sh test.sh
+ echo //
//
+ echo start...
start...
+ echo //
//
+ cat /test.txt
cat: /test.txt: No such file or directory
例2 test2.sh
#set -e
set -x
echo //
echo start...
echo //
cat /test.txt
echo end...
#执行结果
yangyijundeMacBook-Pro:~ yangyijun$ sh test.sh
+ echo //
//
+ echo start...
start...
+ echo //
//
+ cat /test.txt
cat: /test.txt: No such file or directory
+ echo end...
end...
例3 test3.sh
#set -e
#set -x
echo //
echo start...
echo //
cat /test.txt
echo end...
#执行结果
yangyijundeMacBook-Pro:~ yangyijun$ sh test.sh
//
start...
//
cat: /test.txt: No such file or directory
end...