cmd:test 

String compare 

equal:         STRING1 = STRING2
not equal:     STRING1 != STRING2
fret=$?                 # get func ret code
if [ $fret != 0 ] ; then
  # wget returned error
  $echo "Download error.\nNo log written."
else

Numeric compare 

[ "0$show" -ge "2" ] && set -xv
[ "0$show" -eq "1" ] && set -x
INTEGER1 -eq INTEGER2
       INTEGER1 is equal to INTEGER2
-ge  -gt -le -lt -ne

Flag tests 

[-n] STRING
       the length of STRING is nonzero
-z STRING
       the length of STRING is zero
[ -n "$Trig1" -a -n "$Trig1" ] && { action if both trigger is set. }
[ -z "$Trig1" -a -z "$Trig1" ] || { action if either trigger is set }
[ "$Trig1" -o "$Trig1" ] || {
[ -z "$Trig1" -a -z "$Trig1" ] && {
  action if neither trigger is set.
  ie, if either trigger is set, there will be no such action.
}

Connectives 

`! EXPR'
True if EXPR is false.
`EXPR1 -a EXPR2'
True if both EXPR1 and EXPR2 are true.
`EXPR1 -o EXPR2'

True if either EXPR1 or EXPR2 is true.

$ [ "T" -a "" ] && echo yes
$ [ "T" -a "T" ] && echo yes
yes
$ [ "" -a "T" ] && echo yes

tcsh test 

space for if 

host:~/bin>if ( -f dofor  ) echo aaa
aaa
host:~/bin>if ( "a"=="a" ) echo aaa
if: Expression Syntax.
host:~/bin>if ( "a" == "a" ) echo aaa
aaa

test for files 

Usage 

$ touch aa
$ dir aa
-rw-------   1 suntong  glan            0 Dec  7 13:19 aa
$ [ -f aa ] && echo aa
aa
$ [ -s aa ] && echo aa
$

Help 

-e FILE
       FILE exists
-f filename    True if filename  exists  and  is  a  regular
               file.
-s filename    True  if  filename  exists  and  has  a  size
               greater than zero.

test, $var or "$var" 

If you want to test a varible is empty or not, you can either say

[ $var ] or [ "$var" ]

But if you can't guarantee that $var is only one word, you'll get error "[: too many arguments"

documented on: 1999.12.21 Tue 09:20:03