User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 402,918 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,205 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 500 | Replies: 2 | Solved
Reply
Join Date: Nov 2007
Posts: 107
Reputation: k2k is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
k2k k2k is offline Offline
Junior Poster

if statement question

  #1  
Jul 10th, 2008
if [ "$1"="-s" -a -n "$2" ]      # if $1 is string "-s" and $2 is not null 
then 
     string="$2"                    # then string="$2"
else
     echo "error"
     exit 1
fi
echo $string

i expect: foo -not"-s" hi return "error"
however,, no matter what i type after the - , the test will return true. why is that?

i already tried para=`echo "$@"` ; set -- $para still not working properly
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 267
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: if statement question

  #2  
Jul 11th, 2008
Hey there,

You just need to change the

"$1"="-s"

to

"$1" = "-s"

with space on both sides of the = operator and it works well

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Nov 2007
Posts: 107
Reputation: k2k is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
k2k k2k is offline Offline
Junior Poster

Re: if statement question

  #3  
Jul 11th, 2008
Mike,
thanks again for the help. i am more experienced after all these misconceptions.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 4:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC