Shell/Bash: bash if greater than Example

By

Shell/Bash Example: This is the "bash if greater than" Example. compiled from many sources on the internet by SimpleTutorials.org

bash if greater than

if (( a > b )); then
    ...
fi
#Use above example or below one:
if [ "$a" -gt "$b" ]; then
    ...
fi

greater than in script

-eq
is equal to

if [ "$a" -eq "$b" ]

-ne
is not equal to

if [ "$a" -ne "$b" ]

-gt
is greater than

if [ "$a" -gt "$b" ]

-ge
is greater than or equal to

if [ "$a" -ge "$b" ]

-lt
is less than

if [ "$a" -lt "$b" ]

-le
is less than or equal to

if [ "$a" -le "$b" ]

bash if larger than

# In bash, you should do your check in arithmetic context:

if (( a > b )); then
    ...
fi

# For POSIX shells that don't support (()), you can use -lt and -gt.

if [ "$a" -gt "$b" ]; then
    ...
fi



* Summary: This "bash if greater than" Shell/Bash Example is compiled from the internet. If you have any questions, please leave a comment. Thank you!

Others