Fish shell:如何在出错时退出(类似于bash中的set -e)

25
在bash中,你可以在脚本中使用 set -e 来在发生错误时退出:
set -e
cd unexisting-folder
echo "this line will not be printed"

但是在fish shell中,set -e用于删除变量:

set FOO bar
set -e FOO
echo {$FOO} # prints newline

Bash中set -e的Fish等效命令是什么?

1个回答

30

在 fish 中没有相等的功能。https://github.com/fish-shell/fish-shell/issues/805花一点时间讨论一下 fish 版本可能会是什么样子。

如果脚本很短,每行前加上and也许不会太糟糕:

cp file1 file2
and rm file1
and echo File moved

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接