有没有办法通过管道命令来复制其先前的命令退出状态?Bash管道命令及其返回
例如:
#/bin/bash
(...)
function customizedLog() {
# do something with the piped command output
exit <returned value from the last piped comand/script (script.sh)>
}
script.sh | customizedLog
echo ${?} # here I wanna show the script exit value
(...)
我知道我可以简单地检查使用$返回{PIPESTATUS [0]},但我真的想这样做像customizedLog功能是不存在。
有什么想法?
这不是exactely了我的想象,但tottaly解决了我的问题!谢谢Jonathan – RLM
如果必须以这种方式处理_multiple_管道,这尤其方便;作为一种特别的解决方案,OP自己的方法 - 尽管他忽视了它 - 值得重申:echo $ {PIPESTATUS [0]}提供了相同的结果,而无需更改全局shell选项(或者更简单地说,考虑到正在访问_first_数组元素,'echo $ PIPESTATUS'。 – mklement0