имя функции не может вызвать функцию - PullRequest
0 голосов
/ 25 марта 2020

Я написал простую программу, которая запрашивает пользовательский ввод для своих любимых игроков и любимой команды. Я написал этот скрипт, разделяющий их в разные функции. Но, наконец, моя программа не смогла вызвать функцию, пока я вызываю ее по имени, пожалуйста, покажите мне ошибку, которую я сделал.

#!/bin/bash

#asking the user for his user name and the ID


#declearing the password
Password="youilove"

#setting the counter
counter=1

#using until loop for validating the user input

until [ $counter -gt 5 ]
        do
        #asking the user to enter the password to proceed
        #-s refers to the enter the password in silent way
        read -sp "Please enter the password to proceed: " key
        if [ "$key" == "$Password" ]
                then
                    printf "  \n \t\t!!!!!!!!!!!!!!! Hello U-ID: $1 UserName: $2 !!!!!!!!!!!!!!!! \n \t\t\t\t Welcome to My simple program: \t\t\t\t\t\t\t Executed At:$(date)\n"
                    break
                else
                    echo "OOOPs! Wrong one try Again :("
        fi
        ##THE  value of counter keeps on increasing by 1 times each time the loop is entered

                #prompt the user if the user enters the invalid password for three times
            if [ $counter -eq 3 ]
                then
                echo "Your password was incorrect for 3 times : Last 2 chance remaining :- "
            fi

            #prompt the user if the user enters the invalid password for three times

            if [ $counter -eq 4 ]
                then
                echo "last One chance remaining :- "
            fi

                #displaying the message if the user enters the incorrect password continiously for 5 times
            if [ $counter -eq 5 ]
                then
                echo -e " The program has been terminated \n Your password was incorrect for 5 times "
                                exit

            fi
((counter++))
    done

#Step four
#creating the function to display the name of teams

        function askUser(){

            printf " --> (AUS) for Australia \n --> (BAN) for Bangladesh \n --> (NEP) for Nepal \n --> (IND) for India \n --> (ENG) for England\n "

            read -p " Guess one of the best cricket team according to the country code :- " read; choice
        }
            function choice(){

                                #declearing my fav team and storing it in the variable

                        TEAM="ENG"

                                #checking whether the user Input team code matches my fav team or not
                                #reading all the user input value in upper case if they hit the smaller one
                        case ${read^^} in
                                        #this first case become true if the user input is other than england team
                                        #the line is en ded and the askuser function is again called
                                        #THIS process repeat until user enter the correct answer

                                "AUS" | "BAN" | "NEP" | "IND") echo "SORRY!! You Guess the wrong team :(\n"; askUser
                                        ;;
                                "ENG") echo "England is the best cricket team and recently had won the ICC trophy. "
                                        ;;

                                        #this case is true if the user enter the team codes other than above mention
                                *) echo "Please select from the above Teams::):)"; askUser
                        esac

                function selectedPlayers(){
                    printf " --> (PK) for Paras Khadka \n --> (RT) for Ross Taylor \n --> (VK) for Virat Kohli \n --> (BS) for Ben Stokes \n -->(DW) for David Warner \n "

                    #prompting the diaglog and asking the user input in three parameters
                    read -p "Please type code of any three players From listed 5 seperated by space: " one two three
                    if [[ -z "$one" ]] | [[ -z "$two" ]] | [[ -z "three" ]]
                    then 
                    echo "Please select 3 players from above mention list:( "
                    selectedPlayers
                    else
                        PS3="Choose the your Favourite one:- "
                        select Players in ${one^^} ${two^^} ${three^^}
                        do
                            if [[ -z $Players ]]
                            then
                                    echo "Please select from the above mention list"
                                    selectedPlayers
                            elif [ "$Players" == "BS" ]
                            then
                                    cat players/BS #opening the file of Ben Strokes if the user input is BS
                                    exit
                            elif [ "$Players" == "PK" ]
                            then
                                    cat players/PK #opening the file of paras khadka if the user input is PK
                                    exit
                            elif [ "$Players" == "VK" ]
                            then
                                    cat players/VK #opening the file of Virat kohli if the user input is VK
                                    exit

                            else
                            #this else statement is executed if the user choose the players whose files are not been created
                            #here it ask the user if they want to go in the previous step or they want to terminate
                            echo -e "The file matching your information is absent: :(:( "
                            read -p "Do you wish to go to the previous step (Y/N) :-" yn

                                    if [ "$yn" == "y" ]
                                    then
                                    askUser

                                    elif ["$yn" == "n"]
                                    then
                                    exit
                                    else
                                    echo "Please type y for yes and n for no"
                                    fi
                            fi
                            done
                    fi
                    }
                    selectedPlayers
                    }
                    askUser

...