It is currently Thu, 08 Jun 2023 12:19:14 GMT



 
Author Message
 Newb Help with a Basic Bash Script...
Trying to simplify building game servers by using .tar's and copying
stuff around.  I've done good up until the IF/THEN routines and so far
none of the examples I have found can explain this to me.

#This section builds the MOD part of the server

echo    "I will now build the MOD Installation based on your selection
below:"
echo
echo    "1. Team Fortress Classic (TFC)"
echo    "2. Firearms (FA)"
echo    "3. Day of Defeat (DoD)"
echo    "4. Counter-Strike (CS)"
echo
echo -n "Enter the number of the MOD you wish to install:"
     read var_mod

        if ["$var_mod" -eq "1"]
        then
          echo $var_mod
          mkdir /home/$var_username/hlds_l/tfc
          cp -v /home/hl_files/hl/tfc/tfc.tar
/home/var_username/hlds_l/tfc
          cd /home/$var_username/hlds_l/tfc
          tar -xvf tfc.tar
        else
          exit
        fi

It doesn't get past the if [$var_mod -eq "1"] - I get './setup.sh: [1:
command not found' as the error message.  This is my first attempt at
any kind of bash scripting...really this is my attempt at Linux so be
gentle :)



 Sat, 05 Feb 2005 04:32:38 GMT   
 Newb Help with a Basic Bash Script...

That should be if [ "$var_mod" = "1" ]
Spaces around [ and ] are required.

--
M?ns Rullg?rd
m...@users.sf.net



 Sat, 05 Feb 2005 04:35:51 GMT   
 Newb Help with a Basic Bash Script...

Ask on cold.apps in the future.

You need spaces:

  if [ $var_mod -eq 1 ]

Also, note I removed the quotes.  `-eq' operates on integers, not
strings.  It doesn't really matter for -eq, but it might cause bizarre
things to happen if sh starts thinking one of those is supposed to be
a string.

Don't do this, do

  tar -C /home/$var_username/hlds_l/tfc -xvf tfc.tar

It will run twice as fast.

Why this?  You don't _need_ an `else' (and `exit' is supposed to take
an argument).

--
Eric McCoy (reverse "ten.xoc@mpe", mail to "ctr2sprt" is filtered)

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj



 Sat, 05 Feb 2005 04:47:14 GMT   
 Newb Help with a Basic Bash Script...

I meant to mention the reason for this in my post, but I think I
forgot to.  So, to the OP: You need spaces because `if' and `[' must
be distinct tokens, and sh delimits tokens using only spaces.  The
reason they're different tokens is that `[' is basically a program (it
actually is a program, but usually you're using a shell builtin
instead) that performs the enclosed tests.  All `if' does is check the
return code of its argument (`[ ... ]') and figure out where to
branch.

This lets you do things like:

  if grep -q thing file; then
    echo "matched (grep returned success)"
  else
    echo "no match (grep returned $?)"
  fi

And strange but useful things like:

  [ -e filename ] || exit 0

(...which is more commonly written `test -e filename'.)

--
Eric McCoy (reverse "ten.xoc@mpe", mail to "ctr2sprt" is filtered)

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj



 Sat, 05 Feb 2005 04:53:32 GMT   
 
   [ 4 post ] 

Similar Threads

1. Bash Scripting: Little help with basic scripting

2. Basic Bash script question

3. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

4. Newb request: scripts

5. sh newb: case menus w/scripts

6. newb Q, script files

7. Basic scripting help?

8. basic script help

9. Help needed with basic .ksh script logic

10. Basic Shell Script (HELP)


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software