I am writing script, basically it's a calculator for very specific industrial procedure. I want to block alphanumeric input and allow only numerical input. How I do that???? I have used variable for user input but I want to restrict user to numerical input only, since it is a calculator.
For example:
cp=0
echo -n "Please Enter count % "
read cp
numeric=0; while [ $numeric -eq 0 ] ; do read -p "Please enter count % " cp ; if [[ $cp =~ ^[0-9]+$ ]] ; then numeric=1 ; else echo "Error: enter numeric value only" ; fi ; done
– cas Feb 29 '16 at 09:43