简体   繁体   English

根据先前的错误代码退出csh脚本

[英]Exit csh script based on previous error code

I have a shell script running a python script. 我有一个运行python脚本的shell脚本。 In the event of a non-zero exit code I would like the exit the current csh script. 如果退出代码为非零,我希望退出当前的csh脚本。 The example code below in the csh script does not seem to be working. 下面的csh脚本中的示例代码似乎不起作用。

./pythonfile.py
if $? != 0 then
    echo 'Something went wrong!' $?
    exit 1
endif

Most csh versions are actually tcsh . 大多数csh版本实际上是tcsh In tcsh , both $? tcsh $? and $status should work. $status应该起作用。 Looking at the Fixes file, it seems this has been the case since 1992... 查看Fixes文件,看来自1992年以来就是这种情况。

The problem in your code, is that the if statement will override the value of the $status / $? 您的代码中的问题是, if语句将覆盖$status / $?的值$? variables; 变量; you need to use an intermediate variable to store the exit code. 您需要使用一个中间变量来存储退出代码。

false
set code = $?
if $code != 0 then
    echo 'Something went wrong! ' $code
    exit 1
endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM