![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ksh: difference between $* and $@ | JamesByars | Shell Programming and Scripting | 1 | 12-30-2007 10:08 AM |
| Difference between $* and $@ | saneeshjose | Shell Programming and Scripting | 1 | 01-19-2006 08:03 AM |
| Difference between C and C++ | hytechpro | High Level Programming | 2 | 11-29-2005 09:48 PM |
| difference | rajashekaran | UNIX for Advanced & Expert Users | 1 | 04-23-2002 01:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
may be i was not clear
excuse me if i did not clearly stated the prob. Consider this piece of code:
if( $3 == "R001" ) print "xxx"; else print "yyy"; fi my question is why can't I use the following instead of above: if [[ $3 = "R001" ]] print "xxx" else print "yyy" fi Also, is there is a difference in () and [[ ]] in above two examples? Thanks |
|
||||
|
UNIX is an operating system, not a commandline. You seem to be talking about the standard UNIX shell, sh or one of it's clones like bash, but could have as easily been using something like korn... or even been programming in C.... = and == are pretty common.
I've never seen code like your first example, probably because it doesn't work. ( ) brackets aren't statement grouping, they define arrays! Code:
arr=(a = c)
echo ${arr[0]}
echo ${arr[1]}
echo ${arr[2]}
Inside the [[ ]] brackets, == is a pattern matching operator for strings, and = is a straight equality comparison. Outside of there, = is an assignment operator like variable="something" and I don't think == does anything. Also, your if statements aren't quite right. Try this: Code:
if [[ $this = "that" ]]
then
echo "Something"
else
echo "Something else"
fi
Last edited by Corona688; 05-20-2006 at 02:47 AM.. |
|
||||
|
Thanks both of you, for your replies. The examples that I cited were from ksh actually. I did come across some places and found out that == is equality operator used in arirthmatic operations (e.g. to compare two strings) whereas = is simply an assignment operator.
I guess I am still a little bit confused as far as the different brackets are concerned i.e. is my understand correct per following: 1. (commands...) - open a subshell and execute commands in that subshell ?? 2. ((commands...)) - i have no idea about this one. As far as [ $var1 -eq 0 ] and [[ $var1 -eq 0 ]] type of brackets are concerned, i guess they are equivalent and are used to test whether var1 is set to 0. Thanks once again Vikas |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|