有沒有辦法通過管道命令來複制其先前的命令退出狀態?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