Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The title says it all. After Im prompted, I want yes and no to respectively call a function.

# Check to see if you ran this script before

echo
echo I need to know if this is your first time...
while true; do
    read -p "" yn
        case $yn in
            [Yy]* ) new;;
            [Nn]* ) exit;;
                * ) echo "Please answer yes or no.";;
            esac
done

# Define function as new
new (){
    clear; echo As you are new, I will need a few things.
} 

# Define function as root

root(){
    echo "$(tput setaf 6)Hello, world$(tput sgr0)"
}
echo

If the user inputs "y" I want the script to call the function "new". As it is now, the script will try to run a program called "new" that doesn't exist. LOL. Thanks

share|improve this question
    
Did you try calling it with brackets: new()? –  Danatela May 21 at 1:58
    
Yes I did. I got errors. –  rombreaker May 21 at 2:01

1 Answer 1

up vote 2 down vote accepted

You need to define your functions before you call them:

# Define function as new
new (){
    clear; echo As you are new, I will need a few things.
} 

# Check to see if you ran this script before
echo
echo I need to know if this is your first time...
while true; do
    read -p "" yn
        case $yn in
            [Yy]* ) new;;
            [Nn]* ) exit;;
                * ) echo "Please answer yes or no.";;
            esac
done
share|improve this answer
    
Sweet. Thanks Man/Woman –  rombreaker May 21 at 2:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.