[英]Why do I have to type enter to exit my bash script?
When I run my script, I am forced to type enter key, in order exit the script after it completes. 运行脚本时,我被迫键入Enter键,以在完成脚本后退出脚本。 Here's my script:
这是我的脚本:
log_file=/tmp/log.out
rm -f $log_file
setup()
{
exec > >(tee -a ${log_file} )
exec 2> >(tee -a ${log_file} >&2)
}
setup
echo "hello world"
echo "hello again"
I'm testing forcing all echo's to go to stdout and a log file simultaneously. 我正在测试强制所有回显同时进入标准输出和日志文件。 I've seen this behavior before in scripts and have always wondered:
我以前在脚本中已经看到过这种行为,并且一直想知道:
You don't have to hit enter. 您不必按回车键。 You are already at the next prompt.
您已经在下一个提示符下。 Try typing a command and hitting enter.
尝试键入命令并按Enter。
The problem is that you've raced the output and the next prompt being printed to the screen. 问题在于,您已经竞相输出,并且下一个提示被打印到屏幕上。
So your prompt gets printed before the standard error output gets printed so you "lose" your cursor positioning. 因此,在打印标准错误输出之前先打印提示,这样您就可以“丢失”光标的位置。
Clearing the screen, with Ctrl-L say, will also get you "back" to your prompt. 使用Ctrl-L清除屏幕,也会使您“返回”提示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.