![]() |
|
|
|
|
|||||||
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ksh: difference between $* and $@ | JamesByars | Shell Programming and Scripting | 1 | 12-30-2007 06:08 AM |
| Difference between $* and $@ | saneeshjose | Shell Programming and Scripting | 1 | 01-19-2006 04:03 AM |
| Difference between C and C++ | hytechpro | High Level Programming | 2 | 11-29-2005 05:48 PM |
| difference | rajashekaran | UNIX for Advanced & Expert Users | 1 | 04-22-2002 10:59 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
difference between == and =
This is probably a stupid question to ask. But could somebody help me clearly distinguish the difference between these two operators in unix '==' and '='?
|
| Forum Sponsor | ||
|
|
|
|||
|
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-19-2006 at 11:47 PM. |
|
|||
|
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 |
| Thread Tools | |
| Display Modes | |
|
|
|
The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
|
| "inappropriate ioctl for device" 421 service not available, remote server has closed connection autosys awk trim bash eval bash exec bash for loop boot: cannot open kernel/sparcv9/unix close_wait command copy/move folder in unix curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device logrotate.conf lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp batch sftp script snoop unix stale nfs file handle syn_sent tar exclude unix unix .profile unix com unix date command unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi select all vi+substitute+end+of+line+character while loop within while loop shell script |