![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
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?
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
There is no "preference". [[ ]] is required for tests that support booleans like || and &&.
I am assuming you mean either bash or ksh here. |
|
|
|
|
|
#3 |
|
Unverified User
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
Quote:
You can also use -o if [ $a -eq 0 -o $b -eq 0 ] ; then |
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
I personally find using || and && with [[ ]] to be a more "natural way" of testing a condition as opposed to -o and -a using [ ].
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|