2
设置-u用法未按预期工作
我正在学习如何set在脚本中有效使用不同的选项,并且发现set -u如果变量未正确设置(例如删除用户),退出脚本似乎是完美的选择。根据手册页,set -u并set -e执行以下操作... -e Exit immediately if a command exits with a non-zero status. -u Treat unset variables as an error when substituting. 我创建了一个测试脚本来测试此功能,但似乎无法正常工作。也许有人可以更好地向我解释我的问题,而我在哪里曲解?测试脚本如下。谢谢。 set -e set -u testing="This works" echo $? echo ${testing} testing2= echo $? echo ${testing2} testing3="This should not appear" echo $? echo ${testing3} 我希望脚本显示0和“ This …