Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 20, 2012, 11:58 AM   #1
MikePancho
macrumors newbie
 
Join Date: Dec 2012
Help with .command file

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
MikePancho is offline   0 Reply With Quote
Old Dec 20, 2012, 10:15 PM   #2
dmi
macrumors member
 
Join Date: Dec 2010
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 by dmi; Dec 20, 2012 at 11:15 PM.
dmi is offline   0 Reply With Quote
Old Dec 21, 2012, 12:43 AM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
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.
chown33 is offline   0 Reply With Quote
Old Dec 21, 2012, 10:41 AM   #4
pitaya
macrumors member
 
Join Date: Jun 2012
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
pitaya is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:12 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC