Bash Numeric Comparisons

Bash Numeric Comparisons

 Bash Numeric Comparisons

Under the bash shell, you can directly compare numeric values using double parentheses like “((expression))”.

Syntax:

((n1 > n2))

Example:

Compare two values and check if one is greater than the other value. Write below script in compare.sh file.

Now execute this script using the bash shell

$ chmod +x ./compare.sh
$ ./compare.sh
True

Bash – Numeric Comparisons Operators

You can try with many more comparison operators in the bash shell to compare two numeric values.

((n1 == n2))    ## n1 is equals to n2
((n1 != n2))    ## n1 is not equals to n2
((n1 > n2))     ## n1 is greater than n2
((n1 >= n2))    ## n1 is greater or equals to n2
((n1 < n2))     ## n1 is smaller than n2
((n1 <= n2))    ## n1 is smaller than or equals to n2
Reactions

Post a Comment

0 Comments

close