LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2007, 08:58 PM   #1
craigjward
LQ Newbie
 
Registered: Nov 2007
Posts: 24

Rep: Reputation: 15
Case Statement


Hello again.
You guys are probably getting tired of helping me. I'm sorry for being so frusterating. I am running in to some problems with the syntax of my case statement. I don't know what my problem is.

Here is the code for my client so far:
Code:
#!/bin/bash

if [ $# -gt 0 && $1 != -r ]; then
	echo "Usage ./puzzle [rules]"
	exit 1
elif [ $1 = -r ]; then
	./rules
	exit 1
fi

echo "Craig Ward's Puzzle Game"
echo "------------------------"
SOLVED="f"
BLANK="9"

while [ $SOLVED = f ];
do
	./puzzdisp
	echo "Which panel would you like to slide in to the blank? "
	read SLIDE
	
	case $BLANK in
	1 )	if [ $SLIDE -eq 2 || $SLIDE -eq 4 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	2 )	if [ $SLIDE -eq 1 || $SLIDE -eq 3 || $SLIDE -eq 5 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	3 )	if [ $SLIDE -eq 2 || $SLIDE -eq 6]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	4 )	if [ $SLIDE -eq 1 || $SLIDE -eq 5 || $SLIDE -eq 7 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	5 )	if [ $SLIDE -eq 2 || $SLIDE -eq 4 || $SLIDE -eq 6 || $SLIDE -eq 8 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	6 )	if [ $SLIDE -eq 3 || $SLIDE -eq 5 || $SLIDE -eq 9 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	7 )	if [ $SLIDE -eq 4 || $SLIDE -eq 8 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	8 )	if [ $SLIDE -eq 5 || $SLIDE -eq 7 || $SLIDE -eq 9 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	9 )	if [ $SLIDE -eq 6 || $SLIDE -eq 8 ]; then
			mv $SLIDE/* $BLANK/
			mv $BLANK/9 $SLIDE/
		fi
		;;
	esac

	BLANK= $SLIDE
	SOLVED= "t"

	for CHECKDIR in $(seq 9)
	do
		if [ -ne $CHECKDIR/$CHECKDIR ]; then
			SOLVED= "f"
		fi
	done
done

And here is my output
Code:
[: 9: missing ]
[: 9: -r: unexpected operator
Craig Ward's Puzzle Game
------------------------
                            .I$:                                               
                           ?+OO7.                                              
                         .~OOOOZ+,.         ...=I7::..                         
                       . IOOOOOOO7I.   ..,IOOOOOOOOO..                         
                       .:ZOOOOOOOOO=  ..:ZOOOOOOOOOO+..                        
                        IOOOOOOOOZZ~..+=OOOOOOOOOOOOO=..                       
                      .=ZOOOOOOO?:..+ZOOOOOOOOOOZI++,...                       
                      .IOOOOOOO7,..=ZOOOOOOOOO$+:.  ,~======:~,.               
                     ,,$OOOOOOZ~.,,ZOOOOOOOO??:. :++$$ZZZZZZZ$$I+..            
                    .==ZOOOOOO7 .=IOOOOOOOZ~...~7$ZOOOOOOOOOOOOOZ:.            
                    .??OOOOOO$.,7ZOOOOOOO:.:ZZOOOOOOOOOOOOOOOOOOZ:.            
              :??I7?:IIOOOOOO+.~OOOOOOZZ,.~OOOOOOOOOOOOOOOOOOOOOZ:.            
          ..:7OOOOO$:IIOOOOOO,.?OOOOOO~~.:OOOOOOOOOOZOOOOOZOOOOOZ:.            
         .?I$$Z7I???:IIOOOO77.,OOOOOZ:..IOOOOOOZ?:,,,                         
         .$ZO,,. .. .77OOOO++.=OOOOO+.=~OOOOOOI,. .                           
         ,$$O7...  ..77OOOO==.?OOOOZ:.77OOOOI7.,. .                           
          ??OO?,.....77OOOO::.IOOOOI.:ZZOOOZ..~7?~....                        
          ..~OOOZZI~.::7OOO::.$OOOO=.IOOOOI.~~OOOOOO7,..                      
            .~ZOOOO$7==,:IO==.$OOZ$:.7OOOO:...:?OOOOO$,..                     
            ..:$$OOOOZZ$?~,,,.IOOZ$,.7OOOZ..   .:7OOOO7..                     
              ....,7OOOOOOOOOO7=,....7OOO?.      .,,?=Z+=                     
                 ...,IIZOOOOOOOOOZZI=,,,~,..........,$O?=                     
                      .:$OOOOOOOOOOOOOOO$I?~====~+IIOOO,,                     
                        ?OOOOZ$OOOOOOOOOOOOOOOOOOOOOZZ+..                     
                       ..$OOOZ.~OOO$?7OOOO$$$$$$7I?+:...                      
                        .=OOOZ+.$ZOZ,,ZZOO=:::::,. ..                         
                        ..$OOO$.=7OO? 7IOO+         ��������������������������
                         ..77OO$,:~OO$..+OO+..      ��������������������������
                         .,,OOO?:.IOO++.$OZ::       ��������������������������
                            .=OOZ?~.$OOO:,ZO77..    ��������������������������
                            ..IOOZ$:~$OOO,~ZOO?.    ��������������������������
                             ..,ZOOO=.IIZOI.=+..    ��������������������������
                                ~IZOO=..IOO=..      ��������������������������
                                .~+ZOZ:~.7Z~.       ��������������������������
                                 .  =ZOO$...        ��������������������������
                                    .~ZZ$.          ��������������������������
                                      ~:,.          ��������������������������
                                                    ��������������������������
                                                    ��������������������������
Which panel would you like to slide in to the blank? 
6
[: 79: missing ]
puzzle2: 79: 6: not found
puzzle2: 79: 6: not found
puzzle2: 79: t: not found
[: 79: 1/1: unexpected operator
[: 79: 2/2: unexpected operator
[: 79: 3/3: unexpected operator
[: 79: 4/4: unexpected operator
[: 79: 5/5: unexpected operator
[: 79: 6/6: unexpected operator
[: 79: 7/7: unexpected operator
[: 79: 8/8: unexpected operator
[: 79: 9/9: unexpected operator
                            .I$:                                               
                           ?+OO7.                                              
                         .~OOOOZ+,.         ...=I7::..                         
                       . IOOOOOOO7I.   ..,IOOOOOOOOO..                         
                       .:ZOOOOOOOOO=  ..:ZOOOOOOOOOO+..                        
                        IOOOOOOOOZZ~..+=OOOOOOOOOOOOO=..                       
                      .=ZOOOOOOO?:..+ZOOOOOOOOOOZI++,...                       
                      .IOOOOOOO7,..=ZOOOOOOOOO$+:.  ,~======:~,.               
                     ,,$OOOOOOZ~.,,ZOOOOOOOO??:. :++$$ZZZZZZZ$$I+..            
                    .==ZOOOOOO7 .=IOOOOOOOZ~...~7$ZOOOOOOOOOOOOOZ:.            
                    .??OOOOOO$.,7ZOOOOOOO:.:ZZOOOOOOOOOOOOOOOOOOZ:.            
              :??I7?:IIOOOOOO+.~OOOOOOZZ,.~OOOOOOOOOOOOOOOOOOOOOZ:.            
          ..:7OOOOO$:IIOOOOOO,.?OOOOOO~~.:OOOOOOOOOOZOOOOOZOOOOOZ:.            
         .?I$$Z7I???:IIOOOO77.,OOOOOZ:..IOOOOOOZ?:,,,                         
         .$ZO,,. .. .77OOOO++.=OOOOO+.=~OOOOOOI,. .                           
         ,$$O7...  ..77OOOO==.?OOOOZ:.77OOOOI7.,. .                           
          ??OO?,.....77OOOO::.IOOOOI.:ZZOOOZ..~7?~....                        
          ..~OOOZZI~.::7OOO::.$OOOO=.IOOOOI.~~OOOOOO7,..                      
            .~ZOOOO$7==,:IO==.$OOZ$:.7OOOO:...:?OOOOO$,..                     
            ..:$$OOOOZZ$?~,,,.IOOZ$,.7OOOZ..   .:7OOOO7..                     
              ....,7OOOOOOOOOO7=,....7OOO?.      .,,?=Z+=                     
                 ...,IIZOOOOOOOOOZZI=,,,~,..........,$O?=                     
                      .:$OOOOOOOOOOOOOOO$I?~====~+IIOOO,,                     
                        ?OOOOZ$OOOOOOOOOOOOOOOOOOOOOZZ+..                     
                       ..$OOOZ.~OOO$?7OOOO$$$$$$7I?+:...                      
                        .=OOOZ+.$ZOZ,,ZZOO=:::::,. ..                         
                        ..$OOO$.=7OO? 7IOO+         ��������������������������
                         ..77OO$,:~OO$..+OO+..      ��������������������������
                         .,,OOO?:.IOO++.$OZ::       ��������������������������
                            .=OOZ?~.$OOO:,ZO77..    ��������������������������
                            ..IOOZ$:~$OOO,~ZOO?.    ��������������������������
                             ..,ZOOO=.IIZOI.=+..    ��������������������������
                                ~IZOO=..IOO=..      ��������������������������
                                .~+ZOZ:~.7Z~.       ��������������������������
                                 .  =ZOO$...        ��������������������������
                                    .~ZZ$.          ��������������������������
                                      ~:,.          ��������������������������
                                                    ��������������������������
                                                    ��������������������������
Which panel would you like to slide in to the blank?
I'm not asking you to do my homework for me, just let me know where I am going wrong.

Thanks SO much for your continuing patience.
-CJW
 
Old 12-12-2007, 10:12 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
I think it's your if statments with multiple conditions. They should look like this:
Code:
if [ whatever -eq something ] || [ other -eq thing ]; then
   ...
fi
Note the extra ] and [ around the ||.

I think you should also kill the extra space after the number in each case clause, i.e.

Code:
case $BLANK in
    1)
        ...
        ;;
    2)
        ...
 
Old 12-12-2007, 10:30 PM   #3
craigjward
LQ Newbie
 
Registered: Nov 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Hey! Thanks!
That worked! Now i just have to fix my solving statements, and figure out a way to randomize this thing!

Last edited by craigjward; 12-12-2007 at 10:34 PM.
 
Old 12-12-2007, 10:37 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Code:
echo $RANDOM
 
Old 12-12-2007, 10:43 PM   #5
craigjward
LQ Newbie
 
Registered: Nov 2007
Posts: 24

Original Poster
Rep: Reputation: 15
How can i use $RANDOM to randomize a sequence of numbers from 1-9?

Last edited by craigjward; 12-12-2007 at 11:02 PM.
 
Old 12-12-2007, 11:02 PM   #6
craigjward
LQ Newbie
 
Registered: Nov 2007
Posts: 24

Original Poster
Rep: Reputation: 15
more importantly, How can I parse the directory from a variable that holds a file path?

... nevermind

Last edited by craigjward; 12-12-2007 at 11:04 PM. Reason: figured it out
 
Old 12-12-2007, 11:33 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you should probably take time off to read up on some guides, like this one
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM
case statement baks Programming 2 03-15-2007 01:19 PM
How do I use an If statement within a case in a Shell script?? crazygyhrous Programming 7 01-03-2006 06:41 AM
problematic case statement alaios Programming 4 08-24-2005 09:05 AM
bash'ed by case statement??? 3inone Programming 2 04-29-2004 04:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration