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: Davide Brini
Subject: Re: [Help-bash] if and [ ] equivalence
Date: Sun, 11 Mar 2012 20:01:37 +0100

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.



reply via email to

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