Back to Non-Emulation Help

LInux bash script - Validate input

waxzaxOP
#1
I have homework to write a shell script that validates input according to the guidelines below. I've written the script, but the -f option needs work. Its suppose to to be a valid input if its is a letter, what i did is if its a number it wont be valid. therefor a -f option starting with ^ would be valid.GuideLines:---------------------------…
Validate input (validateInput option)
1.write a script which will accept one of 3 options
a.–u uName
b.–g gName
c.–f fullname
2.uName must be
a.between 5-8 characters long
3.gName must be
a.between 3-5 character long
4.fullname must be
a.must be between 8-24 character long and must start with a character
5.the script should echo value 0 if the input is valid, -1 otherwiseScript:-------------------------------…
arg=$1
text=$2
case "$arg" in
"-u") #validate size of uName
if [ ${#text} -lt 5 ] || [ ${#text} -gt 8 ]
then
valid=-1
else
valid=0
fi;;
"-g") #validate size of gName
if [ ${#text} -lt 3 ] || [ ${#text} -gt 5 ]
then
valid=-1
else
valid=0
fi;;
"-f") #check if fullname start with a letter
firstCh=`expr substr $text 1 1`
case "fisrtCh" in
1.2.3.4.5.6.7.8.9.0)
valid=-1;;
*) #validate size of fullname
if [ ${#text} -lt 8 ] || [ ${#text} -gt 24 ]
then
valid= -1
else
valid=0
fi;;
esac
esac
#echo is o if valid, -1 is invalid
echo $valid
--------------------------------------…--How do i change the case option for firstCh to check the alphabet?
Showing posts 1–1 of 1 · This discussion is archivedBack to top