bash 暂停 shell 脚本,直到用户按下 Enter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35075364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pause shell script until user presses enter
提问by Dheeraj
When I am reading a file
当我阅读文件时
sample script
示例脚本
while read file
do
temp = $(echo $file)
read -p "Press Enter to continue"
echo $temp
done < test.txt
I want to pause the script until I press ENTER
我想暂停脚本,直到我按 ENTER
回答by Barmar
read
reads from standard input by default, which is redirected to the file, so it's getting the line from the file. You can redirect back to the terminal:
read
默认情况下从标准输入读取,它被重定向到文件,所以它从文件中获取行。您可以重定向回终端:
read -p "Press Enter to continue" </dev/tty
Another option would be to use a different FD for the file redirection
另一种选择是使用不同的 FD 进行文件重定向
while read -u 3
do
...
done 3< test.txt