bash - Unix shell user input phone number -



bash - Unix shell user input phone number -

i trying write script check whether user has entered valid phone number , check against records.txt file.

i have next code. when come in phone number not recognize it.

i not sure how implement check against text file?

echo "enter phone number xxxxxxxx: " read phonenumber while [ "$phonenumber" != [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ] echo "please come in phone number xxxxxxxx: " read phonenumber done echo $$phonenumber pause

you need include start , end anchors in regex if want validate phone numbers of 8 digits or otherwise, take numbers has more 8 digits.

#!/bin/bash echo "enter phone number xxxxxxxx: " read phonenumber pat="^[0-9]{8}$" while [[ ! $phonenumber =~ $pat ]] echo "please come in phone number xxxxxxxx: " read phonenumber done echo $phonenumber

bash shell unix

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -