在bash输出和错误之间的不匹配订单

问题描述 投票:0回答:1

我在交互shell作为./somescript.sh执行bash命令

它给输出

OS platform is: linux2
killall agent
agent: no process killed

其中,第三行是来自标准错误。

但是,当我执行的子shell作为

var=$('./somescript.sh' 2>&1)
agent: no process killed
OS platform is: linux2
killall agent

并代理原因:没有杀过程中的第一行现在打印?我怎样才能使它保持一致对准他们两个?

编辑:但是当我这样做,我var=$('./somescript.sh' 1>&2)可以看到它给人以正确的顺序输出在bash调试模式。但它没有得到存储在变量var。

bash shell stdout stderr io-redirection
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.