1

I have a list of numbers like this:

limit=( '1' '2' '3' '4' '5' '6' '7' '8' '9' )

Then I want to check the input value to see if it exists in the list. For example:

echo 'Type a number from 1 to 9'
read input
if [ "$input" = "limit" ]
then
exit
else
echo 'Wrong number'

Something like that. If I put limit=9 and use [ "$input" -le "$limit" ] it'll accept numbers like 0, -1, and I don't want that.

codeforester
  • 39,467
  • 16
  • 112
  • 140
Carlos
  • 11
  • 1
  • I don't know what you mean. What do you want it to accept? Do you mean you want to compare input to every element in the array? You would need to use a loop or possible write the limits as regex and then use `=~` – 123 Jun 03 '17 at 19:49
  • Yes I want to compare input to every element in the array, but also want to know how to put more than one element in it. How do I that loop? And I didn't really understood the other method. I tried to this: `if [[ $input =~ [1-31] ]]` but every number and letters with numbers works. – Carlos Jun 03 '17 at 20:26
  • I want it to accept only numbers from 01 to 31. – Carlos Jun 03 '17 at 20:27
  • I don't get what's wrong with "Please help." '.' – Carlos Jun 03 '17 at 21:11

0 Answers0