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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.