Thursday 22 May 2008

Testing variables in bash

So, one of our developers took it upon himself to re-write one of my crappy scripts, and used some odd looking shell 'test' invocations that I'd never seen before.
[ "$FILERTYPE" != "3040" -a "$FILERTYPE" != "3070" "$FILERTYPE" -a != "3070-br" ] && usage

So here we have a logical AND comparison, which calls the function 'usage' if the variable $FILERTYPE does not match any of the valid types. It is the -a which provides the 'AND' capability, alternatively -o gives 'OR' semantics.


I found a nice page from IBM which describes this format and more. IIRC these tests are available in bash but not ksh.

1 comment:

Anonymous said...

burberry outletburberry outletcheap ghd straightenersghd ukugg ukugg ukugg saleugg sale stivali uggugg stivali italidiscount uggcheap ugguggs onlineuggs onlineugg outletugg outletcanada goose for salecheap canada goose