Numeric and string comparisons in Shell scripting
14 Mar 2015The numeric comparisons for shell scripting are:
- numA -eq numB - True if numA and numB are equal
- numA -ne numB - True if numA and numB are not equal
- numA -lt numB - True if numA is less than numB
- numA -gt numB - True if numA is greater than numB
- numA -le numB - True if numA is less than or equal to numB
- numA -ge numB - True if numA is greater than or equal to numB
The string comparisons for shell scripting are:
- strA = strB - True if strA matches strB
- strA != strB - True if strA does not match strB
- strA < strB - True if strA comes before strB in a dictionary order
- strA > strB - True if strA comes after strB in a dictionary order