Control Structures

suggest change

Syntax

Parameters

Parameter to [ or test Details
File operators
-e "$file" Returns true if the file exists.
-d "$file" Returns true if the file exists and is a directory.
-f "$file" Returns true if the file exists and is a regular file.
-h "$file" Returns true if the file exists and is a symbolic link.
String comparators
-z "$str" True if the length of the string is zero.
-n "$str" True if the length of the string is non-zero.
"$str" = "$str2" True if $str is equal to $str2. Not best for integers. It may work, but it will be inconsistent.
"$str" != "$str2" True if the strings are not equal.
Integer comparators
"$int1" -eq "$int2" True if the integers are equal.
"$int1" -ne "$int2" True if the integers are not equal.
"$int1" -gt "$int2" True if int1 is greater than int2.
"$int1" -ge "$int2" True if int1 is greater than or equal to int2.
"$int1" -lt "$int2" True if int1 is less than int2.
"$int1" -le "$int2" True if int1 is less than or equal to int2.

Remarks

There are many comparator parameters available in bash. Not all are yet listed here.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents