I have that For Loop with If condition but it's Not working correctly. It supposes to check each index value if < 255 display Valid else Not Valid. The third and Forth are not correct.
How to fix that issue?
listNumber=(25 255 34 55)
listLength=${#listNumber[@]}
isValid=0
for ((index=0; index<$listLength; index++)); do
itemNumber="$((index+1))"
if [[ ${listNumber[$index]} < 255 ]]; then
echo -e "Item $itemNumber : ${listNumber[$index]} is Valid. \n"
isValid=1
else
echo -e "Item $itemNumber : ${listNumber[$index]} is NOT Valid. \n"
fi
done
Result:
Item 1 : 25 is Valid.
Item 2 : 255 is NOT Valid.
Item 3 : 34 is NOT Valid.
Item 4 : 55 is NOT Valid.