Starting with bash: -lt and -gt arguments

  • I'm starting with bash and I found the following:

    if test $first -lt $second
      echo $first is lower than $second
      if test $first -gt $second
        echo $first is higher than $second
        echo $first and $second are equals

    For reading the script and executing it, I know what it does, but not what -lt and -gt are for.

    Can somebody tell me what is the name of that kind of 'tool' and what they(-lt and -gt) do? Thanks!

    Sorry, but I feel worth pointing out that the `echo` statements in the code answer your question.

    There are missing quotes around the variables

  • cuonglm

    cuonglm Correct answer

    7 years ago

    It's short for less than and greater than. It's used for integer comparison in bash. You can read more by typing man test:

       INTEGER1 -gt INTEGER2
              INTEGER1 is greater than INTEGER2
       INTEGER1 -lt INTEGER2
              INTEGER1 is less than INTEGER2

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM