Posts Tagged ‘prompt user’
December 8, 2016 Leave a comment
I used the following to loop over the lines in a file, while prompting the user for a key press on each iteration:
while read -u 3 line ; do #clear the screen printf "\033c" echo "$line"; echo # do something with the $line here read -n 1 -s -p "[Press any key to continue]" done 3< "some-file.txt"
The reading of the lines is done via file descriptor 3 to avoid interference with the reading of the user’s key presses.