Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help fix this code. I can\'t get the code to do what i want i

ID: 672265 • Letter: C

Question

Can someone please help fix this code. I can't get the code to do what i want it do. I am trying to get a name that begins with a capital letter, follow by lower case letters or a hyphen. I keep getter the same message “First name must begin with capital letter, and must contain only letters and hyphen” even i follow the format. Someone help please!!!

1. Vaildate.sh

echo “Please enter first name”

read first_name

if [ [ $first_name = = ^[A-Z][a-z,-]*] ]

then

echo “Please enter last name”

read last_name

if [ [ $last_name = = ^[A-Z][a-z,-]*] ]

then

echo “Please enter zip code name”

read zip_code

if [ [ $zip_code = =[0-9] [0-9] [0-9] [0-9] [0-9]]

then echo “Please enter email address”

read email

email_regex="^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$"

if [[ $email =~ $regex ]]

then echo “Validated!”

else echo “Invalid Email”

fi

else echo “Zip code must beonly 5 numbers.”

fi

else echo “Last name must begin with capital letter, and must contain only letters and hyphen”

fi

else echo “First name must begin with capital letter, and must contain only letters and hyphen”

fi

Explanation / Answer

change the following code

if [ [ $first_name = = ^[A-Z][a-z,-]*] ]

into

if [ [ $first_name = = ^[A-Z,-][a-z,-]*] ]

Every if is matched with the corresponding fi