【发布时间】:2014-09-04 06:29:03
【问题描述】:
我做了一个简单的脚本:
$ more test.bash
#!/bin/bash
echo test
exit 1
当我运行脚本时,退出状态应该是 1
$ /tmp/test.bash
echo $?
1
但是当我按以下方式运行时
/tmp/test.bash | tr -d '\r' 1>>$LOG 2>>$LOG
echo $?
0
退出状态为0,(不是预期的1)
似乎退出状态来自 tr 命令。 但我想要的是从脚本中获取退出状态 - test.bash。
我需要在我的语法中添加/更改什么以便从脚本而不是从管道之后的命令中获得正确的退出状态?
【问题讨论】:
标签: linux bash shell exit-code