help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to set up a repeat check procedure?


From: Greg Wooledge
Subject: Re: [Help-bash] how to set up a repeat check procedure?
Date: Fri, 30 Dec 2011 10:43:26 -0500
User-agent: Mutt/1.4.2.3i

On Fri, Dec 30, 2011 at 11:32:56PM +0800, lina wrote:
> suppose I have a bit long conditions, do I also no need [ ] for while?

while COMMANDS
do
  COMMANDS
done

COMMANDS can be any list of commands at all.  [ is just one possible
command, and is not always the one you want.

while qstat | grep REM | grep -q ' R '; do
  sleep 10
done

The exit status (the thing that you can see in $?) is checked when the
list of commands is finished.  If the exit status is 0 (true), then bash
executes the body of the while loop, and then returns to the top.  If
the exit status is non-zero (false), then bash skips to the bottom of the
loop.

grep -q sets the exit status to 0 (true) if it matches its pattern against
its input.  That's all you need here.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]