Bash – wait for the user to press any key

Johnny Rosenberg gurus.knugum at gmail.com
Sun Jun 1 22:10:27 UTC 2014


I have something like this:
while read -r -a Line; do
    …
    …
done << "$SomeFile"

Since my script are going to do some dangerous things (deleting files –
hopefully the right ones), I first want to test it by omitting the
dangerous lines and adding a lot of echo lines, letting me know the values
of all important variables.
$SomeFile has a few thousands of lines, so I don't want to go through it
all, but I would like to see the result of maybe the first 20 lines or so.

So I want the script to stop before looping, letting me study all the
variables before going to the next line in the file.

But I figure that if I use ”read” to do that, that ”read” command would
also be fed with $SomeFile, wouldn't it?

So I want something like this:
while read -r -a Line; do
    …
    …
    echo "Press any key to continue"
    SomeCommand
done << "$SomeFile"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20140602/0bb5e6bd/attachment.html>


More information about the ubuntu-users mailing list