Traduisez - Übersetzen - Traduzca - Traduza - Tradurre - Translate

VanLUG Email Archive

VanLUG Mailing List
Re: Gawd Damn bash script.. Again..

New Message Reply About this list Date view Thread view Subject view Author view

Ted Powell (ted@eslvcr.fireplug.net)
Tue, 20 Oct 1998 01:56:08 -0700


On Tue, Oct 20, 1998 at 01:20:14AM -0800, Ian Dobson wrote:
> [...]
> it just loops forever, shouldn't it exit at some point?
> [...]
> while [ $nostrobe=2 ]
> [...]

In a word, no.

You have a single argument inside the [ ] and the rule for a single
argument is that if and only if it is non-null, the result is "true".
Even if your $nostrobe evaluated to the null string, the `=' and the `2'
would still make your argument two bytes long and therefore non-null.

You will probably do better with the three-argument form of [ ]

    while [ $nostrobe = 2 ]

which will give you the test for string equality you were probably
hoping for. Considering that grep -c gives a numeric result, your script
would be more clear if you used a numeric comparison

    while [ $nostrobe -eq 2 ]

Note, by the way, that in

> nostrobe=`ps ax | grep -c "strobe"`

the grep command will sometimes show up in the output of the ps command,
and sometimes not. When it does, that line of ps output will match the
grep pattern

    $ ps ax | grep 'strobe'
    10759 p2 S 0:00 grep strobe

Whether the grep shows up in the output of the ps command really does
vary. Here are two consecutive runs looking for something I knew was
running

    $ ps ax |grep named
      312 ? S 0:48 named
    $ ps ax |grep named
      312 ? S 0:48 named
    10765 p2 S 0:00 grep named

You may want to try something like

    nostrobe=$(ps ax | grep strobe | grep -v grep | wc -l)

-- 
ted@psg.com  http://psg.com/~ted/  (Ted Powell)
If your hard drive crashes, perhaps you have a recent backup. If Earth
crashes, what then? We need off-site backup: Luna, L5, Mars, wherever.


New Message Reply About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b3 on Mon 02 Nov 1998 - 03:23:16 PST