![](/img/trans.png)
[英]Automatic exit from bash shell script on error: set +e does not seem to do the job
[英]Fish shell: how to exit on error (bash set -e)
在bash上,您可以在脚本中使用set -e
以便在出错时退出:
set -e
cd unexisting-folder
echo "this line will not be printed"
但是在set -e
上set -e
用于删除变量:
set FOO bar
set -e FOO
echo {$FOO} # prints newline
什么相当于Bash set -e
on Fish?
在鱼类中没有相当的东西。 https://github.com/fish-shell/fish-shell/issues/805花一点时间讨论这可能是什么样的鱼腥味。
如果脚本很短,请为每行添加前缀and
可能不会太糟糕:
cp file1 file2
and rm file1
and echo File moved
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.