unix – 如何运行tcsh shell命令并有选择地忽略状态?
发布时间:2020-12-15 17:03:39 所属栏目:安全 来源:网络整理
导读:我有一个tcsh shell脚本,我想在大多数时间以非零状态的错误停止,但在某些情况下我想忽略它.例如: #!/bin/tcsh -vxefcp file/that/might/not/exist . #Want to ignore this statuscp file/that/might/not/exist . ; echo "this doesn't work"cp file/that/mu
我有一个tcsh
shell脚本,我想在大多数时间以非零状态的错误停止,但在某些情况下我想忽略它.例如:
#!/bin/tcsh -vxef cp file/that/might/not/exist . #Want to ignore this status cp file/that/might/not/exist . ; echo "this doesn't work" cp file/that/must/exist . #Want to stop if this status is nonzero
我不知道tcsh,但是使用bash,你可以使用
set -e 来做到这一点.设置-e标志后,如果任何子命令失败,bash将立即退出(有关技术详细信息,请参阅手册).未设置时,将继续执行.所以,你可以这样做:
set +e cp file/that/might/not/exist . # Script will keep going,despite error set -e cp file/that/might/not/exist . # Script will exit here echo "This line is not reached" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |