How can we perform numeric comparison in Linux use shell program to explain?
Example: Comparing numbers in bash
Try the following example (type command at terminal): x=51 y=10 [ $x -gt $y ] echo $? Run it as follows: ./script.sh Enter a number (must be greater than 20) : 22 22 is greater than 20. ./script.sh Enter a number (must be greater than 20) : 8 You are not following my instructions.
How do I compare values in bash?
Comparison Operators
When comparing strings in Bash you can use the following operators: string1 = string2 and string1 == string2 – The equality operator returns true if the operands are equal. Use the = operator with the test [ command. Use the == operator with the [[ command for pattern matching.