暂停shell脚本,直到preSS输入while循环
问题描述:
当我读文件
示例脚本
while read file
do
temp = $(echo $file)
read -p "Press Enter to continue"
echo $temp
done < test.txt
我要暂停的脚本,直到我preSS ENTER
I want to pause the script until I press ENTER
答
读
从默认的标准输入,它被重定向到文件读取,因此它得到线从该文件。你可以回重定向到终端:
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 -p "Press Enter to continue" </dev/tty
另一种选择是使用不同的FD的文件重定向
Another option would be to use a different FD for the file redirection
while read -u 3
do
...
done 3< test.txt