jhenders@bogon.com
Tue, 20 Oct 1998 02:49:36 -0700
On Tue, Oct 20/98, Ian Dobson <Ian@fastnet.bc.ca> wrote:
> Argh...!!!!!!
> I know I don't have a clue what I am doing, but why does this not
> work?????
> it just loops forever, shouldn't it exit at some point?
> I've tried changing $nostrobe to 0, 1, 2 and 3.. I couldn't get it to
> ever stop looping..
>
>
> #!/bin/bash
> # script to check to see if strobe is still running
>
> while [ $nostrobe=2 ]
> do
> nostrobe=`ps ax | grep -c "strobe"`
> echo $nostrobe
> echo sleeping
> sleep 5
> done
>
You'll probably get 50 replies to this....
The [ operator is actually a program or bash builtin called test. So man
test would have helped you here. Basically = is a string operator in
test. To test numeric equality, use -eq.
Also though, you seem to be relying on the fact that grep will also
match the grep nostrobe command you are running. I have seen this not
always happen, so I think you are better off to use one of the various
tricks to eliminate the "grep nostrobe" line from the ps output. The
most common is to pipe the output through an extra grep -v grep, but I
prefer using shell protection. You can use "grep to[p]"
Also, when you fix the broken test, your script won't work because the
first test will fail, so you would have to initialize nostrobe before
the while...
so try
nostrobe=1
while [ $nostrobe -eq 1 ]
do
nostrobe=`ps ax| grep -c nostrob[e]`
echo $nostrobe
sleep 5
done
or you could always just do
while ps ax|grep -q nostrob[e]
do
echo nostrobe running
sleep 5
done
--
Artificial Intelligence stands no chance against Natural Stupidity.
GAT d- -p+(--) c++++ l++ u++ t- m--- W--- !v
b+++ e* s-/+ n-(?) h++ f+g+ w+++ y*
This archive was generated by hypermail 2.0b3 on Mon 02 Nov 1998 - 03:23:16 PST