You are on page 1of 4

CODE USED FOR CREATING PROGRAM

#!/bin/bash
Players(){
echo -e " Type Any 3 player codes among five:\c"
read player1 player2 player3
playerchoose=($player1 $player2 $player3)
if [[ ${#playerchoose[@]} -lt 3 ]]
then
echo "Enter atleast three player codes."
Players
elif [[ ${#playerchoose[@]} -gt 3 ]]
then
echo "Enter only three player codes."
Players
elif [[ ${#playerchoose[@]} = 3 ]]
then
if [[ $playerchoose != PK && $playerchoose != VK &&
$playerchoose != DW && $playerchoose != BS && $playerchoose != RT ]]
then
echo "Some player code is not from the table"
Players
elif [[ $player1 == $player2 || $player2 == $player3 ||
$player3 == $player1 ]]
then
echo "Same player repeated more than one time.
Please enter unique player code."
Players
else
PS3="Choose only one number as option: "
select playerNumber in $player1 $player2 $player3 #here select
statement is used to select the answer from array
do
case $playerNumber in #here switch case is used to show the
files according to users input
PK)
cat PK
break
;;
VK)
cat VK
break
;;
RT)
cat RT
break

;;
BS)
if [ ! -f "BS" ]
then
echo "Sorry,No description avaiable
for BS" #these files are absent so it shows message

echo ""
echo ""
echo "REDIRECTING TO COUNTRY
SELCTION..."
countrycode
fi
break
;;

DW)
if [ ! -f "DW" ]
then

echo "Sorry, No description


available for this DW"
echo ""
echo ""
echo "REDIRECTING TO COUNTRY
SELCTION..."
countrycode
fi
break
;;

*)
echo "No player name found" #if user enters
wrong answer like diffrnt character or number it will show messages
Players
break
;;
esac

done
repeat
fi
fi
}
repeat()
{
echo -e "DO you want to return back to country selection(Y/N):\c"
read response
if [[ ${#response[@]} = 0 ]]
then
repeat
fi

until [[ $response = Y || $response = N ]]


do
echo "Answer only in Y or N"
repeat
done

while [[ $response = 'Y' ]]


do
countrycode
done

while [[ $response = 'N' ]]


do
echo "Thank you for your time."
exit
done

}
chooseCountry()
{
echo -e "Guess the best Cricket team from the above given table(Insert
code):\c"
read countrycode
if [[ $countrycode == "NEP" ]]
then
echo ""
echo "Congrats!!! You have choosen the right country code.
Nepal has the best Cricket team."
echo ""
echo "DESCRIPTION OF NEPAL"
echo "===================="
echo ""
echo "The Rhinos and Gorkhalis,represents the country of
Nepal in the international cricket amd is governed by the Cricker
Assossiation of Nepal ( CAN ). Nepal were awarded Twenty international
status by the ICC in June 2014 until the 2015 ICC World Twenty Qualifier. "
echo ""

echo""
echo -e "The list of the five players are: "
echo ""

echo "----------------------------"

echo "| Players Name| Codes| "


echo "|-------------|------------| "
echo -e "|Parash Khadka| PK |"
echo -e "|Virat Kohli | VK | "
echo -e "|David Warner | DW | "
echo -e "|Ben Stokes | BS |"
echo -e "|Ross Taylor | RT |"
printf "%0.s-" {1..28}
echo ""
Players
else
echo "Sorry You have guessed the wrong country code"
chooseCountry
fi
}
secretKey()
{
for i in {1..5}
do
echo -e "Enter your secret key:\c"
read key
if [[ $key = "tabsumrocks" ]]
then
clear
echo "WELCOME TO MY PROGRAM"
echo ""

echo "Name:$1 ID NUmber:$2"


echo ""
echo "You execution time is $(date)"
countrycode()
{
echo ""
echo ""
echo "Here are the list of countries that plays cricket."
printf "%0.s=" {1..52}
echo ""
echo ""
echo " DETAILS "

printf "%0.s*" {1..34}


echo ""
echo ""
printf "%0.s-" {1..29}
echo ""
echo -e "| COUNTRY | CODE|"
echo -e "|---------------------------|"
echo -e "|Australia | AUS|"
echo -e "|Bangladesh | BAN|"
echo -e "|Nepal | NEP|"
echo -e "|India | IND|"
echo -e "|England | ENG|"
printf "%0.s-" {1..29}
echo ""
chooseCountry
}
countrycode
break
else
echo "Please enter correct secret key."
fi
done

}
if [[ "$#" = 2 ]]
then
if [[ $1 != "Tabsum" ]]
then
echo "Invalid username $1. Please enter correct username."
exit
elif [[ $2 != "18030084" ]]
then
echo "Invalid ID number $2. Please enter correct ID
number."
exit
fi
secretKey $1 $2
else
echo "Enter two parameters-| Username and ID Number | "
exit
fi

You might also like