Check variable | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Check variable

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-15-2013
JPad JPad is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 21 September 2013, 5:41 AM EDT
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Check variable

Hi people,

I would like to start a review of my config variable to check whether they have been changed and if not then there is only an echo. If they have been changed to my other commands are executed.

I hope you can help me.

with best regards

JPad

edit:

here my code


Code:
if [ "$USER" == "TYPE_YOUR_USERNAME" ]; then
echo "please edit the config"
else 
my commands
fi


Last edited by JPad; 09-15-2013 at 08:41 AM..
Sponsored Links
    #2  
Old 09-15-2013
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 25 October 2014, 1:14 AM EDT
Location: /dev/ph
Posts: 4,823
Thanks: 64
Thanked 430 Times in 399 Posts
I am not sure what your question is? Your code works.
Sponsored Links
    #3  
Old 09-15-2013
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 24 October 2014, 5:58 PM EDT
Location: Simplicity
Posts: 1,976
Thanks: 127
Thanked 578 Times in 524 Posts
[ ] wants = not ==
    #4  
Old 09-15-2013
JPad JPad is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 21 September 2013, 5:41 AM EDT
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
but i get a error message


Code:
./startscript.sh: 76: [: missing ]
./startscript.sh 80: cd: can't cd to TYPE_YOUR_PATH

and then execute the script my commands

Last edited by Scott; 09-15-2013 at 12:42 PM.. Reason: Code tags
Sponsored Links
    #5  
Old 09-15-2013
wisecracker's Avatar
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 23 October 2014, 3:18 PM EDT
Location: Loughborough
Posts: 642
Thanks: 133
Thanked 136 Times in 113 Posts
Your conditional script works, (OSX 10.7.5 default terminal):-

Code:
Last login: Sun Sep 15 15:34:10 on ttys000
AMIGA:barrywalker~> x="Let it be."
AMIGA:barrywalker~> if [ "$x" == "Let it be." ]; then echo "$x"; else echo "Let it not be."; fi
Let it be.
AMIGA:barrywalker~> if [ "$x" == "Let it not be." ]; then echo "$x"; else echo "Let it not be."; fi
Let it not be.
AMIGA:barrywalker~> _

Your error must be somewhere else and not related to the conditional code you uploaded.
Sponsored Links
    #6  
Old 09-15-2013
JPad JPad is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 21 September 2013, 5:41 AM EDT
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
when i try it, then i got this


Code:
./startscript.sh mainstall
./startscript.sh: 76: [: missing ]
./startscript.sh: 80: cd: can't cd to TYPE_YOUR_PATH
ManiaPlanetServer is downloading.
No passwordentrie for user »TYPE_YOUR_USERNAME«

ManiaPlanetServer is downloaded.

unzip ManiaPlanet
No passwordentrie for user »TYPE_YOUR_USERNAME«
ManiaPlanet was unpacked
ManiaPlanet is given the correct rights.
chmod: access to „ManiaPlanetServer“ not possible: file or directory not found

Ready
Please rename /UserData/Config/dedicated_cfg.default.txt in dedicated_cfg.txt and edit the renamed file.
Push the Startbutton to start ManiaPlanet.

here my code


Code:
mainstall)
    if [ "$USER" = "TYPE_YOUR_USERNAME" ] && [ "$SERVER" = "TYPE_YOUR_SCREENAME_MANIAPLANET" ] && [ "$TITLE" = "TYPE_YOUR_TITLE" ] && [ "$PF" = "TYPE_YOUR_PATH" ] && [ "$MAPLIST" = "TYPE_YOUR_MATCHSETTINGS"]; then
    echo "Please edit the config section!!!!"
    exit 1
    else
    cd $PF
    echo "ManiaPlanetServer is downloading."
    su $USER -c "wget http://files.maniaplanet.com/ManiaPlanet2Beta/ManiaPlanetBetaServer_latest.zip"
    echo ""
        sleep 5
        echo "ManiaPlanetServer is downloaded."
        echo ""
        echo "unzip ManiaPlanet"
        su $USER -c "unzip ManiaPlanetBetaServer_latest.zip"
        sleep 5
        echo "ManiaPlanet was unpacked"
        echo "ManiaPlanet is given the correct rights."
        chmod +x ManiaPlanetServer
        echo ""
        echo "Ready"
        echo "Please rename /UserData/Config/dedicated_cfg.default.txt in dedicated_cfg.txt and edit the renamed file."
        echo "Push the Startbutton to start ManiaPlanet."
    fi

;;

greetz JPad
Sponsored Links
    #7  
Old 09-15-2013
wisecracker's Avatar
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 23 October 2014, 3:18 PM EDT
Location: Loughborough
Posts: 642
Thanks: 133
Thanked 136 Times in 113 Posts
If you are unsure try a simple interactive longhand example first...

On your "if" line which I assume is line 76 there should be a space in the last condition just before "]":-

Code:
............&& [ "$MAPLIST" = "TYPE_YOUR_MATCHSETTINGS" ]; then

Example using OSX 10.7.5 default terminal, bash:-

Code:
Last login: Sun Sep 15 16:03:38 on ttys000
AMIGA:barrywalker~> x="Let it be."
AMIGA:barrywalker~> if [ "$x" == "Let it not be."]; then echo "$x"; else echo "Let it not be."; fi
-bash: [: missing `]'
Let it not be.
AMIGA:barrywalker~> _

Note the space missing before the "]"...

EDIT:
I have a sneaking suspicion your entire "if" condition might still give rise to your error on line 80.

Last edited by wisecracker; 09-15-2013 at 11:33 AM.. Reason: Incorrect indent in example...
The Following User Says Thank You to wisecracker For This Useful Post:
JPad (09-15-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check if a variable is having value anil510 Shell Programming and Scripting 3 02-12-2013 07:00 AM
Check the value of a variable neeraj617 Shell Programming and Scripting 7 04-06-2012 06:25 PM
Check if a variable is zero soujiv Shell Programming and Scripting 8 12-15-2010 04:41 PM
How to check if a variable contains a . gekkos Shell Programming and Scripting 3 11-27-2008 02:00 PM
How to check parameter variable? negixx Shell Programming and Scripting 4 06-10-2005 05:37 PM



All times are GMT -4. The time now is 05:28 AM.