Skip to main content

Check file types and compare values. Returns a status of 0 if the condition evaluates to true, 1 if it evaluates to false.

# To test if a given variable is equal/not equal to the specified string:
[[ $<variable> <==|!=> "<string>" ]]

# To test if a given string conforms the specified glob/regex:
[[ $<variable> <==|=~> <pattern> ]]

# To test if a given variable is [eq]ual/[n]ot [e]qual/[g]reater [t]han/[l]ess [t]han/[g]reater than or [e]qual/[l]ess than or [e]qual to the specified number:
[[ $<variable> -<eq|ne|gt|lt|ge|le> <integer> ]]

# To test if the specified variable has a [n]on-empty value:
[[ -n $<variable> ]]

# To test if the specified variable has an empty value:
[[ -z $<variable> ]]

# To test if the specified [f]ile exists:
[[ -f <path/to/file> ]]

# To test if the specified [d]irectory exists:
[[ -d <path/to/directory> ]]

# To test if the specified file or directory [e]xists:
[[ -e <path/to/file_or_directory> ]]