Write a shell script that demonstrates your ability to organize interactive communication
of its potential user with the UNIX environment in a friendly manner.
1. A user starts the program typing the program name and first his/her first name
and then the ID number as two parameters of the program
2. Program shall ask the secret key to run the program; a user should program this
secret key in advance. If the user enters correct secret key it should move to next
step (3), else it should prompt to enter correct key for four times and then exit the
program.
3. The program welcomes the user somehow mentioning his/her ID number first,
then his/her name and then displays the date and the time of the execution
4. The program displays five codes and names of the five countries team that has
played Football (one code and name per line) and asks the user to guess which
the one is best football team. The codes for Brazil, Argentina, Nepal, China and
England are BRZ, ARG, NEP, CHI and ENG respectively.
1. A user starts the program typing the program name and first his/her first name
and then the ID number as two parameters of the program.
Script :
echo ""
echo " *************************************************************"
echo " -------------------------------------------------------------------------------------------”
echo “ | WELCOME TO THE BEST FOOTBALL TEAM AND PLAYER |
| SELECTION PROGRAM |
echo “ -------------------------------------------------------------------------------------------“
echo “ *********************************************************************** “
#Reading the name of the program.
read -p "Enter the name of your program = " programName
while [[ -z $programName ]]
do
echo " ______________________________________________ "
echo “ | | "
echo " | Sorry! program cannot be empty | "
echo " |_______________________________________________| "
read -p "enter the name of a program = " programName
done
echo -e "\n"
#Reading first name.
read -p "Enter your first name = " fName
while [[ -z $fName ]]
do
echo " _________________________________________ "
echo " | | "
echo " | Sorry! user cannot be empty. | "
echo " |__________________________________________ | "
echo ""
read -p "Enter your first name = " fName
done
echo -e "\n"
#Reading the ID number
read -p "Enter your ID number = " id
while [[ -z $id ]]
do
done
echo " _________________________________________ "
echo " | | "
echo " | Sorry! ID cannot be empty. | "
echo " |__________________________________________| "
echo ""
read -p "Enter your ID number. " id
2. Program shall ask the secret key to run the program; a user should program this
secret key in advance. If the user enters correct secret key it should move to next
step (3), else it should prompt to enter correct key for four times and then exit the
program.
3. The program welcomes the user somehow mentioning his/her ID number first,
then his/her name and then displays the date and the time of the execution.
Script:
function startProgram(){
a=5 #Defining variable a and its value as 5
while [ $a -gt 0 ]
do
echo -e "\n"
read -sp "Enter the secret key of a program.(Secret key is hidden) = "
secretKey #Reading the secret key.
if [[ ( $secretKey == "sharon") ]]; # If the secret key is "sharon" than user is
login successfully.
then
echo " "
echo " __________________________________________ "
echo " | | "
echo " | Sucessfully login | "
echo " | | "
echo " |__________________________________________| "
echo " "
echo -e "\n"
echo " Congratulations. Your attempt to login this program is
successful."
echo " ID Number = $ID"
echo " First Name = $fName"
# Displays the execution date.
echo " Execution Date = "$(date '+%d/%m/%d')
#Displays the execution time.
echo " Execution Time = "$(date '+%H:%M:%S')
break
else
((a--)) #Decreasing the value of 'a' by 1.
if [ $a -gt 0 ] #if secret key is invalid , a user gets four more chances
then
echo ""
echo “ ____________________________________"
echo " | | "
echo " | Invalid key! | "
echo " | Please try it again | "
# Displaying the chances left to run program
echo " | You have only $a chances left |"
echo " |___________________________________|"
echo ""
fi
fi
done
if [ $a -eq 0 ] #If the value of a is 0 then the user cannot login to the
program.
then
echo " "
echo “ _____________________________________"
echo " | | "
echo " | Sorry! | "
echo " | Login time is out | "
echo " |_____________________________________| "
exit 0
fi
4. The program displays five codes and names of the five countries team that hasplayed Football (one code and name per line) and asks the user to guess which
the one is best football team. The codes for Brazil, Argentina, Nepal, China and
England are BRZ, ARG, NEP, CHI and ENG respectively.
5. After the user typed the country code, if the option is correct, the program informs
about it and gives one two sentences explaining about some of the descriptions/
characteristics of the chosen team, otherwise the program warns about a
mistake, and the user will guess until the correct option is chosen.
Script:
function selectTeam() {
echo " ____________________________________________ "
echo " | | "
echo " | Guess the best team and enter code below. | "
echo " |___________________________________________ | "
echo -e "\n"
echo " -------------------------------------------------------"
echo " | Country Name | Country Code |"
echo " --------------------------------------------------------"
echo " | Brazil | BRZ |"
echo “ | Argentina | ARG |"
echo " | Nepal | NEP |"
echo " | China | CHI |"
echo " | England | ENG |"
echo " ---------------------------------------------------- “
echo -e "\n"
while :
do
echo " ------------------------------------------------------"
read -p " Enter the best team code here= " teamCode
echo " ------------------------------------------------------"
case "$teamCode" in
"BRZ" )
echo " -------------------------------------------------"
echo " | Correct team code |"
echo " -------------------------------------------------"
echo “ _________________________________________"
echo " | |"
echo " | The Brazil national footaball team represents Brazilian "
echo " | men's international football an is admistrated by the |"
echo " | Brazilian Football Confederation(CBF). They have been a
|"
echo " | member of FIFA since 1923 and a member of CONMEBOL
since |"
echo "| 1916 since 1916. Brazil is the most successful national |"
echo " | team in the FIFA World Cup being crowned winner five
times |"
echo "| : 1992, 1970, 1994 and 2002. |"
echo “ ____________________________________________|"
sleep 0.4
selectBestPlayer
break
;;
"ARG"|"NEP"|"CHI"|"ENG")
# Displaying message to the user incase of incorrect code
echo " ----------------------------------"
echo " | Invalid code |"
echo " | Please try again |"
echo " ----------------------------------"
;;
*)
echo " --------------------------------------- "
echo " | Please enter valid code | "
echo " -------------------------------------- "
echo " "
;;
esac
done
}
Comments
Leave a comment