From 3c63897ea385097a2aaed4ba6e6e4bdf7c3aa417 Mon Sep 17 00:00:00 2001 From: iProbe Date: Fri, 8 Dec 2023 11:34:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'shell/shell=E4=B8=AD?= =?UTF-8?q?=E7=9A=84set.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/shell中的set.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 shell/shell中的set.md diff --git a/shell/shell中的set.md b/shell/shell中的set.md new file mode 100644 index 0000000..a2b95cc --- /dev/null +++ b/shell/shell中的set.md @@ -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 +``` +