0

I.I need to validate if characters a-z are entered it will reprompt. Below is a snippet of my script

wh

While [true]
    do
      mainMenu # menu function
      read $opt # read option from menu
      if [ $opt -eq 0 ]; then
        exit
      elif [ $opt -gt 4 -o $choice -lt 1 ]; then
        read $opt
      elif [ $opt -eq [a-zA-Z]]; then # this line doesn't work need to validate
        read $opt
      else
        break
      fi
    done
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Watael
0

hi,

of course: [a-zA-Z] is text, and -eq is arithmetic operator!

I'd add a case/esac to split that messy if elif.. and consider $opt is a number or not:

While :
do
   mainMenu # menu function
   read $opt # read option from menu
   case $opt in 
      [0-9]) if test $opt -eq 0
             then exit
             elif test $opt -gt 4 || test $choice -lt 1
             then read opt
             fi

      [a-zA-Z]) read opt;;
      *) break;;
   esac
done

Edited by Watael

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.