Re: while loop



Ed Morton wrote:

kevin_m wrote:

Thanks for the reply,


You're welcome, but please don't top-post. Fixed below.

Ed Morton napísal(a):

kevin_m wrote:

Hi all,
I'm trying to "echo" some informations in a while loop, in ksh script.
I want to quit (only the while loop), if the user enter some key...
Can anyone help me accomplish this task?
Thanks


It seems like there must be more to your loop than you've told us so
far. Apart from the part about breaking out of the loop, do you want to
just do this:

while [ 1 ]
do
echo "All work and no play makes Jack a dull boy"
done

Or do you want to take some kind of a break (e.g. to read something from
a file or from stdin, or to just do the echo every N seconds, or
something) between the iterations of "echo"s, e.g.:

while [ 1 ]
do
echo "All work and no play makes Jack a dull boy"
sleep 1
done

The answer to that question will determine the solution(s).

Ed.


> I want exactly something like you wrote:
> while [ 1 ]
> do
> echo "All work and no play makes Jack a dull boy"
> sleep 1
> done

In bash you can specify a timeout value for the read command, so you can do:

resp=""
while [ "$resp" != "q" ]
do
echo "All work and no play makes Jack a dull boy"
read -t 1 resp
done

Regards,

Ed.

And if your read doesn't support a timeout value, see the suggestion in the thread at http://tinyurl.com/kykzu

Ed.
.



Relevant Pages

  • Re: Program effeciency due to comments..
    ... echo "All work and no play makes Jack a dull boy" ...
    (comp.unix.shell)
  • Re: Reading a variable line by line with while loop
    ... done < `echo "$Variable"` ... echo "History - $History" ... The last echo command returns nothing, but if I put an echo command in ... the loop either before, or after the replace spaces command, it echoes ...
    (Ubuntu)
  • Re: 2.6.16-rc4: known regressions
    ... either with a command line argument, or with just the early bootup initrd ... Is there a way to tell the kernel about which is the root device other ... a loop with one second delay. ... echo -n "Waiting for root device to appear" ...
    (Linux-Kernel)
  • Re: [PHP] 2 errors I can not understand
    ... echo is not a function. ... multiple args is probably insignificant, ... and super-long loop... ... function isprime ...
    (php.general)
  • Re: while loop
    ... I'm trying to "echo" some informations in a while loop, ... echo "All work and no play makes Jack a dull boy" ...
    (comp.unix.shell)