[plug] problem found in "if" statement

James Devenish devenish at guild.uwa.edu.au
Fri Aug 29 14:02:15 WST 2003


In message <sf4e43d3.044 at mmtnetworks.com.au>
on Thu, Aug 28, 2003 at 06:02:46PM +0800, Jon  Miller wrote:
> The output from the awk statement is an integer,

No, the textual output from awk is text (i.e. a string) -- it is a
"textual representation" of an integer. Only the return code is a
true integer.

> If the return value is blank then it needs to run the rest of the
> script commands.  If it's an integer it needs to exit.

I mailed this to the list a while ago: use the -z test. It will test the
difference between "empty" and "non-empty". Alternatively, you can use
Bernd's suggestion of utilising sed or awk to actually check that the
text contains only numeric digits. But for the purpose of check for the
mere *presence* of a PID, there is no need to do any of this. Just use
pgrep's return code and *ignore* its textual output *completely*!

In message <sf4e42e4.043 at mmtnetworks.com.au>
on Thu, Aug 28, 2003 at 05:58:54PM +0800, Jon  Miller wrote:
> > >>> John.Usher at perth.maptek.com.au 8:58:11 AM 28/08/2003 >>>
> > try:
> > if [ "$vMLSTAT" -ge 0 ]; then
> Tried that and got an error stating:
> [: -ge: unary operatory expected

John is correct: numerical comparisons use -ge! But the "unary operator
expected" error is due to $vMLSTAT being empty (remember: it is NOT an
integer, it is a STRING, strings can be EMPTY, and EMPTY is NOT an
integer).




More information about the plug mailing list