【发布时间】:2013-08-08 16:49:29
【问题描述】:
我有一个大型 bash 脚本,我想将所有 stdout/stderr 全局重定向到一个文件,除了一些进度指示器,例如特定的回显消息。例如,考虑以下脚本
#!/bin/bash
# all stdout and stderr go to out.log
exec &> out.log
special_echo "starting"
# many other commands go here
# which output both the stdout and stderr
# also some special_echo commands in here,
# for example
echo "msg1"
special_echo "middle"
echo "msg2" >&2
special_echo "finished"
当它运行时输出应该是
$ ./script
starting
middle
finished
$
但是,out.log 应该包含
msg1
msg2
如何实现special_echo 功能?我尝试使用文件描述符并对其进行回显,但无法将其显示在屏幕上。
有没有办法在不将重定向附加到每一行或做类似answer 的事情的情况下实现这一点?
【问题讨论】:
标签: bash