我有一个我要解析的命令。但是,在某些情况下,此命令将提示是否需要用户干预(例如,是/否,[输入]继续等)。如何在显示所有输出时捕获此命令的输出?如果命令等待输入,那么当命令真正处于提示状态时,它看起来就像正忙着执行。
$ program_output=$(command)
# Program stalls here performing a `read` but user doesn't see anything
# User finally presses [Enter]
$
$ command
Warning: Some warning message. Continue? (Y/n)
Y #User-input
Created http://example/subprogram/id/
$
答案 0 :(得分:0)
如果您正在捕获标准输出,您可以在stderr上打印一条消息以提供反馈:
echo -n 'Warning: Some warning message. Continue? (Y/n) ' >&2
read -r answer