Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 29th, 2005, 2:21 PM   #1
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
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?
aznluvsmc is offline   Reply With Quote
Old Jan 3rd, 2006, 9:10 AM   #2
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
There is no "preference". [[ ]] is required for tests that support booleans like || and &&.

I am assuming you mean either bash or ksh here.
jim mcnamara is offline   Reply With Quote
Old Jan 3rd, 2006, 4:06 PM   #3
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
I've used single brackets with || and &&.
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted.
Got 'Nux?—GNU/Linux and other free software support.
It's GNU/Linux, not just Linux.
a thing is offline   Reply With Quote
Old Jan 4th, 2006, 12:55 PM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
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 [[ ]]
jim mcnamara is offline   Reply With Quote
Old Jan 17th, 2006, 6:00 PM   #5
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
I personally find using || and && with [[ ]] to be a more "natural way" of testing a condition as opposed to -o and -a using [ ].
aznluvsmc is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:17 AM.

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