repeat command until keypressed?

Eugeneapolinary Ju eugeneapolinary81 at yahoo.com
Fri Oct 23 14:21:46 UTC 2009


wow..

thanks for the idea!

Thank you!

--- On Fri, 10/23/09, Karl Auer <kauer at biplane.com.au> wrote:

From: Karl Auer <kauer at biplane.com.au>
Subject: Re: repeat command until keypressed?
To: ubuntu-users at lists.ubuntu.com
Date: Friday, October 23, 2009, 12:21 PM

On Fri, 2009-10-23 at 04:41 -0700, Eugeneapolinary Ju wrote:
> How can I write a bash script, that will repeat the commands
> until any key is pressed?

This little script will wait one second for you to press a key (has to
be a character key, not something like shift), and if you don't it just
loops.


#!/bin/bash
while [ true ] ; do
   read -t 1 -n 1
   if [ $? = 0 ] ; then
      exit ;
   else
      echo waiting...
   fi
done



"read" returns zero if input was received, non-zero if the input times
out.

"-t 1" says wait only one second for input before timing out.

"-n 1" says accept a single character of input, don't wait for a whole
line.

Very important point: This really has to be bash! The simplified read in
dash (the default Linux shell) is not good enough.

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)                   +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/                  +61-428-957160 (mob)

GPG fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF


-----Inline Attachment Follows-----

-- 
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/20091023/68206657/attachment.html>


More information about the ubuntu-users mailing list