I have an array with some elements and in some function the following:
echo -n "Select the option: "
read option
echo "option: '${option}'"
echo "option: '$option'"
if [[ $option -ge 1 && option -le ${#array[@]} ]]; then
echo "go go go"
...
else
...
fi
About the input - if a number higher than the array's length/size is written then the else block is executed as expected - same for a negative number - or even 0. Until here all is expected
But if a simple character as s, d is written then the if block is executed and it is not expected.
select the option: d
option: 'd'
option: 'd'
go go go
According with my understanding -ge and -le is applied for numbers - so it should fail if a character is used how a number comparison - it should go straight to the else block
How to fix this?
$option =~ ^(0|[1-9][0-9]*)$$after&&inif [[ $option -ge 1 && option -le ${#array[@]} ]]; then. Intentionally? Why notif [[ $option -ge 1 && $option -le ${#array[@]} ]]; then?