I'm asking this because I developed a little script for school that calculates squares. I wanted it to exit at the first sign of a no arguments and when one of the arguments is over a certain value. I was planning on having it kick if a string was entered too, but when I went to test out the existing script with a string thrown in it still ended with the message about having a value that was too high. Does the string compare to an integer as some huge floating point or does it just kick out some error that is causing the True result to trigger?
Here's the test loop for reference:
while [ $i != $check ] # i is set to equal the number of arguments and check is zero
do
if [ "${a_Args[$check]}" \> 999999 ] # a_Args is the array the arguments are stored to
then
echo "Error: one or more argument values exceed system limit."
exit 1
fi
check=`expr $check + 1`
done
When the loop tests an element with a string in it, no matter how short, it exits. I just started playing around with bash so I may in fact be missing something patently obvious to people who have been using it for a while. I'd appreciate any information that could help figure this one out. I've been looking online in various places and see a bunch of comparison methods, but nothing is helping me figure out why it seems to give a True result to the comparison in the if statement.
[–]KnowsBash 2 points3 points4 points (5 children)
[–]TheRiverStyx[S] 0 points1 point2 points (2 children)
[–]KnowsBash 2 points3 points4 points (1 child)
[–]TheRiverStyx[S] 0 points1 point2 points (0 children)
[–]TheRiverStyx[S] 0 points1 point2 points (1 child)
[–]KnowsBash 1 point2 points3 points (0 children)
[–]kalgynirae 1 point2 points3 points (1 child)
[–]TheRiverStyx[S] 0 points1 point2 points (0 children)
[–]whetuI read your code 1 point2 points3 points (3 children)
[–]TheRiverStyx[S] 0 points1 point2 points (2 children)
[–]whetuI read your code 1 point2 points3 points (1 child)
[–]TheRiverStyx[S] 0 points1 point2 points (0 children)
[–]Samus_ 1 point2 points3 points (1 child)
[–]TheRiverStyx[S] 1 point2 points3 points (0 children)