|
|
Difference between test, [..] and [[...]]
Hello Everybody,
I am new to Unix. Oflate i have been analyzing lot of shell scripts...
but couldn't find the difference between the following commands.
1) if test "expr"; then do something; else do something else; fi
2) if [ "expr" ]; then do something; else do something else; fi
3) if [[ "expr" ]]; then do something; else do something else; fi
Can any one brief me on this thing. Thankyou.
|
|
0
|
|
|
|
Reply
|
reddy.preetham (1)
|
3/6/2006 1:53:51 PM |
|
Preetham Reddy wrote:
> Hello Everybody,
>
> I am new to Unix. Oflate i have been analyzing lot of shell scripts...
> but couldn't find the difference between the following commands.
>
> 1) if test "expr"; then do something; else do something else; fi
>
> 2) if [ "expr" ]; then do something; else do something else; fi
>
> 3) if [[ "expr" ]]; then do something; else do something else; fi
>
>
> Can any one brief me on this thing. Thankyou.
Nice resource for scripting in general:
http://www.tldp.org/LDP/abs/html/index.html
and for your question in particular:
http://www.tldp.org/LDP/abs/html/testconstructs.html
|
|
0
|
|
|
|
Reply
|
shakahshakah
|
3/6/2006 3:14:18 PM
|
|
On 2006-03-06, Preetham Reddy wrote:
> Hello Everybody,
>
> I am new to Unix. Oflate i have been analyzing lot of shell scripts...
> but couldn't find the difference between the following commands.
>
> 1) if test "expr"; then do something; else do something else; fi
>
> 2) if [ "expr" ]; then do something; else do something else; fi
>
> 3) if [[ "expr" ]]; then do something; else do something else; fi
1 and 2 are the same ('[' is the same as 'test').
3 is a non-portable syntax found in bash and ksh. The example you
gave has the same effect as 1 and 2, but '[[..]]' has more features
than 'test'. They are mostly available through other (standard)
syntax such as 'case'.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
|
|
0
|
|
|
|
Reply
|
Chris
|
3/8/2006 10:17:15 AM
|
|
|
2 Replies
474 Views
(page loaded in 0.005 seconds)
Similiar Articles: Difference between test, [..] and [[...]] - comp.unix.programmer ...Hello Everybody, I am new to Unix. Oflate i have been analyzing lot of shell scripts... but couldn't find the difference between the following comman... What's the difference between TEST and CMP ? - comp.lang.asm.x86 ...Hi, I'm a rookie in assembly language, this question just came up my mind, so I post it here in the hope that someone would explain more details about... Re: cross-over study: 2 sample t-test vs paired t-test - comp.soft ...One additional question, both tests are testing for a 'dfference', either a difference between means in (1) or a difference from 0 in (2). How do I make a claim about ... 900% difference between backup and restore rates using ufsdump and ...Difference between test, [..] and [[...]] - comp.unix.programmer ... 900% difference between backup and restore rates using ufsdump and ... 900% difference between backup ... Weighted paired t-test - comp.soft-sys.matlabHi, I wanted to perform a weighted paired t-test. In my understanding, the only difference between a weighted and unweighted t-test is the fact ... Log Rank Test - comp.soft-sys.sasDear all: This is the sample data i have . I am trying to model this data and see if there is any difference between the treatment groups and fi... Major differences between MIPS and ARM - comp.archMajor differences between MIPS and ARM - comp.arch What's the difference between TEST and CMP ? - comp.lang.asm.x86 ... Major differences between MIPS and ARM - comp.arch ... the difference between two forms of logic and - comp.unix.shell ...Test regex in KSH - comp.unix.shell > > =A0echo ${NUMBER_TO_TEST} | egrep -q "^[-+]?([1-9][0 ... the difference between two forms of logic and - comp.unix.shell ... Difference between SAR and IDIV??? - comp.lang.asm.x86Difference between test, [..] and [[...]] - comp.unix.programmer ... Difference between SAR and IDIV??? - comp.lang.asm.x86 Hello all, can anyone explain the difference ... Nonparametric, paired test with unequal sample size? - comp.soft ...Peter pointed out that a paired two-sample test is generally the same as a one-sample test on the difference between the two samples. Can you take all differences of a ... Difference Between Z-test and T-test | Difference Between | Z-test ...Z-test Vs T-test Sometimes, measuring every single piece of item is just not practical. That is why we developed and use statistical methods to solve Difference Between Survey & Diagnostic Tests | eHow.comSurvey tests and diagnostic tests are both critical for their purposes of searching for scientific answers. However, they can serve very different purposes. Survey ... 7/25/2012 8:15:14 AM
|
|
|
|
|
|
|
|
|