$?在shell脚本中

时间:2016-03-29 20:55:25

标签: linux shell

我试图找出这意味着什么/如何$?填充在linux中,我尝试进行搜索,但是如果有人可以澄清那会很棒:

exitstat=$?

if [ $exitstat -ne 0 ]
  then
    echo -e "Could Not Extract"
    echo -e "Aborting Script `date`"
    exit $exitstat
fi

上面的代码是:

_xfile << %%  2> /files/thefile-7000.log |  _afile -x -r 10 2> /files/thefile-7000.log > /files/thefile.7000
OperatorHigh = $finalnumber
%%

1 个答案:

答案 0 :(得分:4)

$?扩展到最近前台命令的退出状态。

由于您之前的命令是管道,退出状态是管道中最后一个命令的状态 - 在这种情况下,_afile - 除非 pipefail设置了shell选项,在这种情况下,管道中其他地方的故障也可以使退出状态非零。