Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MikePancho

macrumors newbie
Original poster
Dec 20, 2012
4
0
God I'm new to mac (I just got one) and I'm having trouble programming this .command file. It's a weird file (considering it tells jokes that make no sense) but when I open it, it just closes right away.

Heres the code;
Code:
#!/bin/bash
PS3='Please enter your choice: '
options=("Polar bears in a tub" "Guys on a porch" "Squirrels in a tree" "People in a garden" "People in a restaurant" "Like us on Facebook" "Watch Star Wars" "Rate" "Donate" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Polar bears in a tub")
            say "So... There were two polar bears sitting in a tub. One said, Pass the soap, The other one said, No soap, RADIO! HAH HAH! YOUR A NUB!"
            ;;
        "Guys on a porch")
            say "So... There were two guys sitting on a porch. One said, Pass the beer, The other one said, No beer, WHISKY! HAH HAH! YOUR A NUB!"
            ;;
        "Squirrels in a tree")
            say "So... There were two squirrels sitting in a tree. One said, Pass the leaves, The other one said, No leaves, BRANCHES! HAH HAH! YOUR A NUB!"
            ;;
        "People in a garden")
            say "So... There were two people sitting in a garden. One said, Tell me a joke, The other one said, No jokes, FUNNIES! HAH HAH! YOUR A NUB!"
            ;;
        "People in a restaurant")
            say "So... There were two people sitting in a restaurant. One said, Pass the tacos, The other one said, No tacos, PIZZA! HAH HAH! YOUR A NUB!"
            ;;
        "Like us on Facebook")
            echo "I tricked you, we don't have a Facebook!"
            ;;
        "Watch Star Wars")
            echo "This is the whole star wars movie, once you start it you can not stop it. Are you sure you want to do this?
            PS3='Please enter your choice: '
			options=("Yes" "No")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"Yes")
        				telnet towel.blinkenlights.nl
            			;;
        			"No")
            			;;
            ;;
        "Rate")
            echo "Rate the jokes:"
            echo "Polar bears in a tub"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good
            			;;
        			"5")
            			echo "Great"
            			;;
            echo "Guys on a porch"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good
            			;;
        			"5")
            			echo "Great"
            			;;
            echo "Squirrels in a tree"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good
            			;;
        			"5")
            			echo "Great"
            			;;
            echo "People in a garden"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good
            			;;
        			"5")
            			echo "Great"
            			;;
            echo "People in a restaurant"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good
            			;;
        			"5")
            			echo "Great"
            			;;
            ;;
        "Donate")
            open -a Safari https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=4dHtIuFUeTRnqOqzLu5wJ897QJSEwsbk3oaO1-gf2FHZTVDJhRJlVHr5iee&dispatch=5885d80a13c0db1f8e263663d3faee8d0b7e678a25d883d0fa72c947f193f8fd
            ;;
        "Quit")
            killall Terminal
            ;;
        *) echo Invalid option;;
    esac
done
 

dmi

macrumors regular
Dec 21, 2010
162
33
You have unmatched quotes, case's and do's
Code:
#!/bin/bash
PS3='Please enter your choice: '
options=("Polar bears in a tub" "Guys on a porch" "Squirrels in a tree" "People in a garden" "People in a restaurant" "Like us on Facebook" "Watch Star Wars" "Rate" "Donate" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Polar bears in a tub")
            say "So... There were two polar bears sitting in a tub. One said, Pass the soap, The other one said, No soap, RADIO! HAH HAH! YOUR A NUB!"
            ;;
        "Guys on a porch")
            say "So... There were two guys sitting on a porch. One said, Pass the beer, The other one said, No beer, WHISKY! HAH HAH! YOUR A NUB!"
            ;;
        "Squirrels in a tree")
            say "So... There were two squirrels sitting in a tree. One said, Pass the leaves, The other one said, No leaves, BRANCHES! HAH HAH! YOUR A NUB!"
            ;;
        "People in a garden")
            say "So... There were two people sitting in a garden. One said, Tell me a joke, The other one said, No jokes, FUNNIES! HAH HAH! YOUR A NUB!"
            ;;
        "People in a restaurant")
            say "So... There were two people sitting in a restaurant. One said, Pass the tacos, The other one said, No tacos, PIZZA! HAH HAH! YOUR A NUB!"
            ;;
        "Like us on Facebook")
            echo "I tricked you, we don't have a Facebook!"
            ;;
        "Watch Star Wars")
            echo "This is the whole star wars movie, once you start it you can not stop it. Are you sure you want to do this?"
            PS3='Please enter your choice: '
			options=("Yes" "No")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"Yes")
        				telnet towel.blinkenlights.nl
            			;;
        			"No")
            			;;
			esac
			done
            ;;
        "Rate")
            echo "Rate the jokes:"
            echo "Polar bears in a tub"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good"
            			;;
        			"5")
            			echo "Great"
            			;;
			    esac
			done
            echo "Guys on a porch"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good"
            			;;
        			"5")
            			echo "Great"
            			;;
			    esac
			done
            echo "Squirrels in a tree"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good"
            			;;
        			"5")
            			echo "Great"
            			;;
			    esac
			done
            echo "People in a garden"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good"
            			;;
        			"5")
            			echo "Great"
            			;;
			    esac
			done
            echo "People in a restaurant"
            PS3='Please enter your choice: '
			options=("1" "2" "3" "4" "5")
			select opt in "${options[@]}"
			do
    			case $opt in
        			"1")
            			echo "Horrible"
            			;;
        			"2")
            			echo "Not so good"
            			;;
        			"3")
            			echo "Ok"
            			;;
        			"4")
            			echo "Good"
            			;;
        			"5")
            			echo "Great"
            			;;
			    esac
			done
            ;;
        "Donate")
            open -a Safari https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=4dHtIuFUeTRnqOqzLu5wJ897QJSEwsbk3oaO1-gf2FHZTVDJhRJlVHr5iee&dispatch=5885d80a13c0db1f8e263663d3faee8d0b7e678a25d883d0fa72c947f193f8fd
            ;;
        "Quit")
            killall Terminal
            ;;
        *) echo Invalid option;;
    esac
done
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
First, identify which OS version you're using.

When I try simpler command files on several different OS X versions, they all work.

Maybe you did something to your shell environment or profile.

Copy and paste this into a Terminal window (note, in a window, not a .command file), then copy and paste the output in a reply here:
Code:
ls -la ~


Second, make a much simpler script file. Give it one 'echo' command with an identifiable output string. Test it. Post the results.

Next, make a slightly bigger script. Give it only a single level of select, case, etc. Then test that one.

If it works as expected, then build it up from there, testing again after every addition.

If it doesn't work as expected, then post the simplest version that shows the problem, and describe what you expected to happen.

If this is your creation, then why weren't you testing it along the way, in its smaller and simpler forms? If it's not your creation, then post the URL where you got it from.
 

pitaya

macrumors member
Jun 17, 2012
34
0
There are a bunch of problems with the script.

Look at your nested case statements. They need a matching esac. Similarly, do/done. You're also missing a closing double quote for the 'echo "Good' lines. There's probably some other stuff too.

Oh, and you probably shouldn't killall Terminal
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.