全部博文(930)
分类:
2010-11-15 19:00:52
Numerical Comparison | ||
---|---|---|
< | less than | $bad = $gpa < 1.5; |
<= | less than or equal | $good = 3.5 <= $gpa; |
> | greater than | $very_good = $gpa > 3.9; |
>= | greater than or equal | $not_bad = $gpa >= 2.3; |
== | equals to | $perfect = $gpa == 4; |
!= | not equal to | $not_perfect = $gpa != 4; |
<=> | compare. The result of this operator is equal to either 1, 0, or -1. It's equal to 1 if the first operand is greater than the second, zero if they are equal, and -1 if the second is greater than the first. | $comparison = $a <==> 123; |
String Comparison | ||
lt | less than | $before = $name lt "b"; |
le | less than or equal | $a_name = $name le "a"; |
gt | greater than | $after = $name gt "Tester"; |
ge | greater than or equal | $after_P = $name ge "O"; |
eq | equivalent to | $is_Bob = $name eq "Bob"; |
ne | not equal to | $not_Bob = $name ne "Bob"; |
cmp | The string comparison operator evaluates to either 1, 0, or -1. | $comparison = $name cmp "Bob"; |
[ "$shvar" = "fox" ] String comparison, true if match.
[ "$shvar" != "fox" ] String comparison, true if no match.
[ "$shvar" = "" ] True if null variable.
[ "$shvar" != "" ] True if not null variable.
[ "$nval" -eq 0 ] Integer test; true if equal to 0.
[ "$nval" -ge 0 ] Integer test; true if greater than or equal to 0.
[ "$nval" -gt 0 ] Integer test; true if greater than 0.
[ "$nval" -le 0 ] Integer test; true if less than or equal to 0.
[ "$nval" -lt 0 ] Integer test; true if less than to 0.
[ "$nval" -ne 0 ] Integer test; true if not equal to 0.
[ -d tmp ] True if "tmp" is a directory.
[ -f tmp ] True if "tmp" is an ordinary file.
[ -r tmp ] True if "tmp" can be read.
[ -s tmp ] True if "tmp" is nonzero length.
[ -w tmp ] True if "tmp" can be written.
[ -x tmp ] True if "tmp" is executable.