Pause Shell script until Press Enter in while loop

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

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

回答1:

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 

Another option would be to use a different FD for the file redirection

while read -u 3 do     ... done 3< test.txt 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!