Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause shell script until user presses enter

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

like image 636
Dheeraj Avatar asked Jan 29 '16 01:01

Dheeraj


1 Answers

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
like image 112
Barmar Avatar answered Sep 22 '22 16:09

Barmar