Re: Bash – wait for the user to press any key

Johnny Rosenberg gurus.knugum at gmail.com
Mon Jun 2 17:34:58 UTC 2014


2014-06-02 18:54 GMT+02:00 Johnny Rosenberg <gurus.knugum at gmail.com>:

> 2014-06-02 17:35 GMT+02:00 John Howe <madlinuxman at hotmail.com>:
>
>  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"
>>
>> Ooops, I guess I accidently added a ”<” too much…
>
>
>>
>>
>>
>>
>>  I use.........
>>
>> # init
>> function pause(){
>>    read -p "$*"
>> }
>>
>>     do some work here
>>
>> read -p "Press [Enter] key to continue or Crtl c to exit..."
>>
>
> I suppose you mean ”pause” instead of ”read -p”, right?
>
>>
>> Hope it helps
>>
>
> Maybe it should, but it doesn't seem to work the way I was talking about
> in my original post. Here's are my test files:
> <File>
> # looptest.sh
>

The line above isn't a part of the file, sorry for adding it here…


> #!/bin/bash
>
>
> function pause(){
>     read -p "$*"
> }
>
> while read x; do
>     echo $x
>     pause "Press any key to continuea"
> done < Information
> </File>
>
> <File>
> # Information
>

Same with the line above, it isn't a part of the file.


> This
> text
> is
> very
> very
> interesting
> annoying
> </File>
>
> <Execution>
> $ ./looptest.sh
> This
> is
> very
> annoying
> $
> </Execution>
>
> The text is printed immediately, no pause or anything. So it seems, just
> like I said in my original post, like the file (”Information” in this case)
> does the input for me. Is there a way to force a read command to read from
> the keyboard in a situation like this?
>
>
> Johnny Rosenberg
>
>
I just gave up the whole thing and used Yad instead:

pause() {
    yad --image="info"       \
          --title='Pause!'       \
          --text="$1"            \
          --button="Next":0
}


Johnny Rosenberg


>
>> --
>> Best Regards
>> John
>>
>> *Windows users take note: all emails from this system are scanned for viruses using ClamAV and the latest definitions*
>>
>>
>> --
>> ubuntu-users mailing list
>> ubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20140602/069bddbe/attachment.html>


More information about the ubuntu-users mailing list