Conditional expressions

For use with if and test.

File Conditionals

If file exists and is a block special file.

-b 

If file exists and is a character special file.

-c 

If file exists and is a directory.

-d 

If file exists.

-e 

If file exists and is a regular file.

-f 

If file exists and its set-group-id bit is set.

-g 

If file exists and is a symbolic link.

-h 

If file exists and is a named pipe (FIFO).

-p 

If file exists and is readable.

-r 

If file exists and its size is greater than zero.

-s 

If file descriptor is open and refers to a terminal.

-t 

If file exists and its set-user-id bit is set

-u 

If file exists and is writable.

-w 

If file exists and is executable.

-x 

If file exists and is a symbolic link.

-L 

If file exists and is a socket.

-S 

Variable Conditionals

If the length of string is zero.

-z

If the length of string is non-zero.

-n

Variable Comparisons

Equal to.

var = var2

Not equal to.

var != var2

Equal to (algebraically).

var -eq var2

Not equal to (algebraically).

var -ne var2

Greater than (algebraically).

var -gt var2

Greater than or equal to (algebraically).

var -ge var2

Less than (algebraically).

var -lt var2

Less than or equal to (algebraically).

var -le var2