Operator | Description | Example |
---|---|---|
= | is equal to | [ $a = $b ] |
== | is equal to | [ $a == $b ] |
!= | is not equal to | [ $a != $b ] |
> | is greater than, in alphabetical order | [ $a > $b ] |
< | is less than, in alphabetical order | [ $a < $b ] |
-z | has zero length | [ -z $a ] |
-n | has non-zero length | [ -n $a ] |
str | is not an empty string | [ $a ] |
Operator | Description | Example |
---|---|---|
-eq | is equal to | [ $a -eq $b ] |
-ne | is not equal to | [ $a -ne $b ] |
-gt | is greater than | [ $a -gt $b ] |
-ge | is greater than or equal to | [ $a -ge $b ] |
-lt | is less than | [ $a -lt $b ] |
-le | is less than or equal to | [ $a -le $b ] |
> | is greater than | (( $a > $b )) |
=> | is greater than or equal to | (( $a >= $b )) |
< | is less than | (( $a < $b )) |
<= | is less than or equal to | (( $a <= $b )) |
Operator | Description | Example |
---|---|---|
! | logic NOT | [ ! $a ] |
-o | logic OR | [ $a -lt 20 -o $b -gt 100 ] |
-a | logic AND | [ $a -lt 20 -a $b -gt 100 ] |
Operator | Description | Example |
---|---|---|
-b file | checks if file is a block special file | [ -b file ] |
-c file | checks if file is a character special file | [ -c file ] |
-d file | checks if file is a directory | [ -d file ] |
-f file | checks if file is an ordinary file | [ -f file ] |
-g file | checks if file has its set group ID (SGID) bit set | [ -g file ] |
-k file | checks if file has its sticky bit set | [ -k file ] |
-p file | checks if file is a named pipe | [ -p file ] |
-t file | checks if file descriptor is open and associated with a terminal | [ -t file ] |
-u file | checks if file has its Set User ID (SUID) bit set | [ -u file ] |
-r file | checks if file is readable | [ -r file ] |
-w file | checks if file is writable | [ -w file ] |
-x file | checks if file is executable | [ -x file ] |
-s file | checks if file has size greater than 0 | [ -s file ] |
-e file | checks if file exists | [ -e file ] |