LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 01-13-2004, 11:52 PM   #1
e1000
Member
 
Registered: Oct 2003
Location: California
Distribution: Ubuntu
Posts: 582

Rep: Reputation: 30
simple bash script not working.


all my knowledge on shell scripting is based on reading scripts and that micro shell scripting hoto at TLDP, so anyways I tried to make a shell script that would start my bzflag server for me but when I run it, it just doesnt work, doesnt give an error either, it just freezes
here it is

---------CODE-------------------
#!/bin/bash
read MAP GTP
GAME=
if ["$GTP" = "flag"]; then
---$GAME=-c
---echo CTF mode selected
else if ["$GTP" = "rabbit"]; then
---$GAME=-rabbit
---echo rabit mode selected
else
---echo FFA slected
fi
bzfs $GAME -f bad +f good -fb -h -j -ms 15 +r +s 3 -sb -sl GM 50 -sl L 50 -st 8 -t -tk -world /home/evan/docs/maps/$MAP
----------/CODE-----------------------
(i didnt use a code box cuz i like word wrap, so I placed --- where tabs are)
also, unless I specify rabbit or flag, i want $GAME to have no value

Any ideas why its not working?
 
Old 01-14-2004, 12:22 AM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
Theirs quite a few things wrong with your script, your missing a fi before the last else, you don't read files like that. You quote strings for comparision, and not for your echo's etc...

So I fixed it

---CODE---
#!/bin/bash
if [ -e GTPFILE ]; then
---exec 0< GTPFILE
---read GTP <&0
---exec 0>&-
---if [ -z $GTP ]; then
------echo "FFA selected"
---else
------if [ $GTP = flag ]; then
---------GAME=-c
---------echo "CTF mode selected"
------else
---------if [ $GTP = rabbit ]; then
------------GAME=-rabbit
------------echo "rabit mode selected"
---------fi
------fi
---fi
else
---echo "FFA selected"
fi
if [ -e MAPFILE ]; then
---exec 0< MAPFILE
---read MAP <&0
---exec 0>&-
fi
bzfs $GAME -f bad +f good -fb -h -j -ms 15 +r +s 3 -sb -sl GM 50 -sl L 50 -st 8 -t -tk -world /home/evan/docs/maps/$MAP
---CODE---
 
Old 01-14-2004, 12:52 AM   #3
e1000
Member
 
Registered: Oct 2003
Location: California
Distribution: Ubuntu
Posts: 582

Original Poster
Rep: Reputation: 30
ok, im convinced, bash scripting is awesome and im also convinced that i cant learn it by reading a bunch of scripts made by other people and some little mini tuts.

where did you learn to make scripts like that? was it a book or was it a combo of many tuts (or mabee that one HUGE shell scripting tut like the one at TLDP)
 
Old 01-14-2004, 12:59 AM   #4
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
It was at TLDP from the Advanced Bash-Scripting Guide. I only learn't bash scripting about three weeks ago, To write a script to download configure and compile KDE3.2 from CVS. Thats about it, and I though it would be useful to learn.

But then again I know a lot of programming languages already, once you've learn't a couple, the rest are easy. It doesn't matter what you start with either.

The file stuff is on page part 3 page 16 "I/O Redirection".
 
Old 01-14-2004, 01:09 AM   #5
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
A couple of bits of advice as well. Before trying your script test it by using echo instead of the actual command. so
bzfs $GAME -f....
becomes
echo "bzfs $GAME -f...

Then you can execute your script and know its working before hand. Also use this script

Code:
#!/bin/bash
if [ -e GTPFILE ]; then
   exec 0< GTPFILE
   read GTP <&0
   exec 0>&-
   if [ -z $GTP ]; then
      echo "FFA selected"
   else
      case "$GTP" in
         "flag" )
            GAME=-c
            echo "CTF mode selected"
         ;;
         "rabbit" )
            GAME=-rabbit
            echo "rabit mode selected"
         ;;
         * )
            echo "error: unknown mode $GTP selected"
            exit
         ;;
      esac
   fi
else
   echo "FFA selected"
fi

if [ -e MAPFILE ]; then
   exec 0< MAPFILE
   read MAP <&0
   exec 0>&-
   bzfs $GAME -f bad +f good -fb -h -j -ms 15 +r +s 3 -sb -sl GM 50 -sl L 50 -st 8 -t -tk -world /home/evan/docs/maps/$MAP
else
   echo "No map selected"
fi
As it will report errors, and you'll know why things aren't working as expected. Also its easier to expand for more options.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple bash script lp449 Linux - Networking 3 08-02-2005 05:25 PM
Simple bash script Soulful93 Programming 1 06-04-2005 08:26 PM
Simple Bash Script Help njdownes Programming 2 03-05-2005 08:35 AM
Simple Bash Script dmedici Programming 9 12-31-2004 04:48 AM
Help with simple bash script - please tw001_tw Linux - Software 5 12-19-2004 10:02 PM


All times are GMT -5. The time now is 12:43 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration