help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] if and [ ] equivalence


From: DJ Mills
Subject: Re: [Help-bash] if and [ ] equivalence
Date: Mon, 12 Mar 2012 00:22:36 -0400

On Sun, Mar 11, 2012 at 3:01 PM, Davide Brini <address@hidden> wrote:
> On Sun, 11 Mar 2012 09:00:28 -0600, Bill Gradwohl <address@hidden> wrote:
>
>> If I have a function that can optionally accept parameters, I can write :
>>
>>    if func ; then
>> and the equivalent can be said:
>>
>>    [ func ] &&
>
> It's not equivalent. If it looks like it is, it's by accident.
> The (rough) equivalent is
>
> func && ...
>
>> If, however, func needs to have a passed parameter,
>>    [ func parm ] &&
>>
>> fails with "unary operator expected"
>>
>> Is there any way to specify the [ ] method with a passed parameter?
>
> You want to test the exit status, so you want
>
> if func parm; then ....
>
> or
>
> func parm && ...
>
> The [ ... ] construct is not used to do what you're trying to do. "man
> test" should explain it.
>
> --
> D.
>

Or ''help test'', for the bash equivalent. All 'if' does is check the
exit status of a command. '[' is just a command, like any other. Same
with '&&'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]