Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   Which test syntax to use? (http://www.programmingforums.org/showthread.php?t=7754)

aznluvsmc Dec 29th, 2005 2:21 PM

Which test syntax to use?
 
I found out that you can use [ test-condition ] or [[ test-condition ]] in shell scripts . To me the [[ test-condition ]] syntax seems to resemble other programming lanuage syntax by support && and || logical operators. Is one syntax preferred over the other?

jim mcnamara Jan 3rd, 2006 9:10 AM

There is no "preference". [[ ]] is required for tests that support booleans like || and &&.

I am assuming you mean either bash or ksh here.

a thing Jan 3rd, 2006 4:06 PM

I've used single brackets with || and &&.

jim mcnamara Jan 4th, 2006 12:55 PM

Quote:

Originally Posted by a thing
I've used single brackets with || and &&.

Depends on which shell you use - ksh requires it.

You can also use -o
:

if [ $a -eq 0 -o $b -eq 0 ] ; then
which does not require [[ ]]

aznluvsmc Jan 17th, 2006 6:00 PM

I personally find using || and && with [[ ]] to be a more "natural way" of testing a condition as opposed to -o and -a using [ ].


All times are GMT -5. The time now is 4:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC