How do you compare two no in shell scripts?

1 answer

Answer

1167991

2026-05-12 23:40

+ Follow

To compare two numbers in a shell script, you can use conditional expressions with the [ or test command. For example, you can use -eq for equality, -ne for inequality, -lt for less than, -le for less than or equal to, -gt for greater than, and -ge for greater than or equal to. Here’s a simple example:

<code class="language-bash">if [ "$num1" -eq "$num2" ]; then

echo "Numbers are equal." else echo "Numbers are not equal." fi

</code>

Make sure to use spaces around the brackets and the operators.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.