添加 'shell/shell中的set.md'
This commit is contained in:
parent
4249c1249b
commit
3c63897ea3
1 changed files with 24 additions and 0 deletions
24
shell/shell中的set.md
Normal file
24
shell/shell中的set.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
**1.shell遇到错误的时候不会停止,接着执行下面的shell命令的时候有时候是一种非预期的行为,可能会产生破坏性,所以我们写的总是小心翼翼。**
|
||||||
|
**2.shell的调试比较困难,尤其是当我们在linux服务器上使用vim来进行shell的编写的时候更会存在这种情况,只能靠不断的加一些echo命令来尝试看看发生了什么**
|
||||||
|
set可以避免以上问题。
|
||||||
|
有以下几个常用命令
|
||||||
|
```shell
|
||||||
|
# +,-表示模式的开关,其中-为开启,+为关闭
|
||||||
|
# 遇到错误后脚本会直接退出,不会继续往下执行
|
||||||
|
set -e
|
||||||
|
# 关闭以上模式
|
||||||
|
set +e
|
||||||
|
|
||||||
|
# set -e无法处理管道错误,set -o主要处理管道异常问题
|
||||||
|
set -o pipefail
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
|
# 若变量不存在,脚本退出(默认忽略)
|
||||||
|
set -u
|
||||||
|
set +u
|
||||||
|
|
||||||
|
# 增加调试
|
||||||
|
set -x
|
||||||
|
set +x
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue