Pause Shell script until you press Enter during a loop

When i read the 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 we press ENTER

+4
source share
1 answer

readreads the standard default input, which is redirected to a file, so it gets the line from the file. You can redirect back to the terminal:

read -p "Press Enter to continue" </dev/tty

Another option is to use another FD to redirect files

while read -u 3
do
    ...
done 3< test.txt
+10
source

Source: https://habr.com/ru/post/1626466/


All Articles