The Github Experiment By Ajay Gupta

Numeric and string comparisons in Shell scripting

The numeric comparisons for shell scripting are:

  1. numA -eq numB - True if numA and numB are equal
  2. numA -ne numB - True if numA and numB are not equal
  3. numA -lt numB - True if numA is less than numB
  4. numA -gt numB - True if numA is greater than numB
  5. numA -le numB - True if numA is less than or equal to numB
  6. numA -ge numB - True if numA is greater than or equal to numB


The string comparisons for shell scripting are:

 

  1. strA = strB - True if strA matches strB
  2. strA != strB - True if strA does not match strB
  3. strA < strB - True if strA comes before strB in a dictionary order
  4. strA > strB - True if strA comes after strB in a dictionary order