【发布时间】:2015-07-10 21:35:21
【问题描述】:
我有以下两个 bash 脚本:
一个.bash:
#!/bin/bash
echo "I don't control this line of output to stdout"
echo "I don't control this line of output to stderr" >&2
echo "I do control this line of output to fd 5" >&5
callone.bash:
#!/bin/bash
# here I try to merge stdout and stderr into stderr.
# then direct fd5 into stdout.
bash ./one.bash 1>&2 5>&1
当我这样运行它时:
bash callone.bash 2>stderr.txt >stdout.txt
stderr.txt 文件如下所示:
I don't control this line of output to stdout
I don't control this line of output to stderr
I do control this line of output to fd 5
标准输出为空。
我希望将“控制”行仅输出到 stdout.txt。
进行更改的限制是:
- 我可以更改 callone.bash 中的任何内容。
- 我可以更改我控制的 one.bash 中的行。
- 我可以在 one.bash 中添加与文件描述符 5 相关的 exec。
- 我必须按照指示运行脚本。
[编辑] 这个用例是:我有一个脚本可以执行各种其他脚本的运行,这些脚本可以输出到 stderr 和 stdout。但我需要确保用户只能看到控制良好的消息。所以我将控制良好的消息发送到 fd5,其他所有内容(stdout 和 stderr)都发送到日志。
【问题讨论】:
标签: bash