[plug] Shell Scripting Confusion

Russell Steicke r.steicke at bom.gov.au
Thu Feb 10 11:33:40 WST 2000


I think the point was that the obvious way to write ``greater than'' could
lead to some strange, unexpected behaviour.

$ [ 1 -gt 2 ] && echo one bigger || echo two bigger
two bigger
$ ls
$ [ 1 > 2 ] && echo one bigger || echo two bigger
one bigger
$ ls
2
$ 



On Thu, Feb 10, 2000 at 11:00:00AM +0800, Nick Bannon wrote:
> On Wed, Feb 09, 2000 at 02:26:11PM +0800, John Summerfield wrote:
> [...]
> > It's nothing to do with the question at hand, BUT
> > 
> > In this context
> > 	[ $n > $y ]
> > the greather-than symbol is a redirection operator.
> 
> ">" is not a valid operator to the "test" program. You're looking for
> "-gt".
> 
> The "test" program is also known as "[", so unless your shell does it
> for you (as it often does) ;
> 
>   [ "$n" -gt "$y" ] && echo larger || echo smaller
> 
> means "run the [ program with the parameters "$n" -gt "$y" ], if
> successful run "echo larger" OR if all of the following failed, run
> "echo smaller". The final ] is mainly cosmetic.
> 
>   test "$n" -gt "$y" && echo larger || echo smaller
> 
> works just the same.
> 
> Nick.
> 
> -- 
>   Nick Bannon  | "I made this letter longer than usual because
> nick at it.net.au | I lack the time to make it shorter." - Pascal
> 
-- 
Russell Steicke

-- Fortune says:
PLUG IT IN!!!



More information about the plug mailing list