Shell Scripting Linux Part1 Write a script that asks the us

Shell Scripting -- Linux

Part-1 Write a script that asks the user to enter his name. Read the name. Then asks the user to enter the phone number. Then read the phone number. Append the name and phone number (separated by a comma) to a file called phones.

Part -2 Modify the above script so that it will have a loop and continuously ask the user to enter for name and phone number appending it to the file phones. Each time, you should ask the user if you want to continue (Y/N). Name this script script1. Test the script and make sure it runs OK.

Part 3-3 Create a script called phoneMenu to display a menu of choices as follows:

Enter Data

Show names

Show phone numbers

Then display the command saying please enter the choice. Read the choice.

If the choice is 1, then execute script1.

If the choice is 2 then write the command to cut the names from file phoneMenu and display that.

If the choice is 3 then write the command to cut the phones from the phoneMenu and display that.

Solution

//shell script1

#!/bin/bash
echo -n \"Enter name: \"
read name
echo $name
echo -n \"Enter phone number: \"
read phone
echo $phone

--------------------------------------------

//shell script2

#/bin/bash                                                                                                                                                   

while true                                                                                                                                                   

do   

echo -n \"Enter name: \"

read name

echo $name

echo -n \"Enter phone number: \"

read phone

echo $phone

echo \"Do you want to continue: \"

read choice

echo $choice

echo -e $name $phone >> \"phones\"

if [ $choice == \"n\" ]

    then

echo \"Quit entering name and phone\"

break

fi

done  

------------------------------------------------------------

//script3

echo \"###########Menu###################\"
echo \"1. Enter Data 2. show names 3. show phone numbers 4. quit\"
while [ true ]
do
echo \"Enter you choice \"
read choice
if [ $choice == 1 ]
then
echo \"./main.sh\"
fi
if [ $choice == 2 ]
then
echo \"show names\"
cut -c 1-6 phones
fi
if [ $choice == 3 ]
then
echo \"show phone numbers\"
cut -c 7-17 phones
fi
echo \"test\"
if [ $choice == 4 ]
then
echo \"Quit\"
break
fi
echo \"test\"
done

Shell Scripting -- Linux Part-1 Write a script that asks the user to enter his name. Read the name. Then asks the user to enter the phone number. Then read the
Shell Scripting -- Linux Part-1 Write a script that asks the user to enter his name. Read the name. Then asks the user to enter the phone number. Then read the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site