Bash – wait for the user to press any key

John Howe madlinuxman at
Mon Jun 2 15:35:38 UTC 2014

On 01/06/14 23:10, Johnny Rosenberg wrote:
> 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"
I use.........

# init
function pause(){
    read -p "$*"

     do some work here

read -p "Press [Enter] key to continue or Crtl c to exit..."

Hope it helps

Best Regards

*Windows users take note: all emails from this system are scanned for viruses using ClamAV and the latest definitions*

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ubuntu-users mailing list