Dhe*_*raj 8 bash shell while-loop
当我正在阅读文件时
示例脚本
while read file
do
temp = $(echo $file)
read -p "Press Enter to continue"
echo $temp
done < test.txt
Run Code Online (Sandbox Code Playgroud)
我想暂停脚本,直到我按ENTER键
Bar*_*mar 18
read默认情况下从标准输入读取,重定向到文件,因此它从文件中获取行.您可以重定向回终端:
read -p "Press Enter to continue" </dev/tty
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用不同的FD进行文件重定向
while read -u 3
do
...
done 3< test.txt
Run Code Online (Sandbox Code Playgroud)