shell - Comparing numbers in Bash -
I am starting to learn how to write scripts for the bass terminal, but I can not compare how to compare To work properly I believe that this is very basic for many of you, I can not find the answer to my question anywhere (or at least I do not fully know what to find I'm using the script):
echo" enter two numbers "; Read a b; Echo "a = $ a"; Echo "b = $ b"; If [$ a \ & gt; $ B]; Then echo is "bigger than A B"; The second echo "B is more than one"; Fi;
The problem I have is that it compares the number to the first digit, 9 is greater than 10000, but larger than 19. How can I convert numbers into one type? To compare the truth? I know that this is probably a bit nervous, but any help would be appreciated!
In the Bash, you should check in:
if ((A and G; b) ); So do not support (())
for the POSIX shells -lt
and -gt
. if ["$ a" -gt "$ b"]; Then ...
You can get a complete list of comparisons operator with the support exam
.
Comments
Post a Comment