On Fri, 19 Mar 2021 23:26:01 +0100
Pierre Labastie <pierre.labas...@neuf.fr> wrote:

> On Fri, 2021-03-19 at 07:24 -0400, Scott Andrews wrote:
> > On Fri, 19 Mar 2021 07:09:06 +0100
> > Pierre Labastie <pierre.labas...@neuf.fr> wrote:
> >   
> > > 
> > > Using brackets depends on "something". If something is a
> > > predicate, you need brackets. If something is a (compound)
> > > command, no brackets. I've not looked in details at the "if" in
> > > the boot scripts, but they must be correct in this respect,
> > > since they seem to work...
> > >   
> > 
> > By brackets are you talking about [ ] or [[ ]]?
> > 
> > if [ something ]; then this; fi,
> > 
> > Really means
> > 
> > if test something; then this; fi
> > 
> > [ is actually test, and the [ must be followed by ]
> > 
> > [[ ]]  is an expression
> > 
> > See the gnu bash reference manual for clarification.
> >   
> 
> Here is an experiment:
> ---
> pierre [ ~ ]$ toto () {
> > return 1
> > }  
> pierre [ ~ ]$ if toto; then echo true; else echo false; fi
> false
> pierre [ ~ ]$ if [ toto ]; then echo true; else echo false; fi
> true
> ---
> 
> Pierre
> 
Here is a more complete test:


toto () {
        return 1
}  
gogo () {
        return 0
}

echo "toto test"

if toto; then echo true; else echo false; fi

if [ toto ]; then echo true; else echo false; fi

if test toto; then echo true; else echo false; fi

if [[ toto ]]; then echo true; else echo false; fi

echo "gogo test"

if gogo; then echo true; else echo false; fi

if [ gogo ]; then echo true; else echo false; fi

if test gogo; then echo true; else echo false; fi

if [[ gogo ]]; then echo true; else echo false; fi

Results:
toto test
false
true
true
true
gogo test
true
true
true
true

Here is what the gnu bash manual states:

test
[
test expr
Evaluate a conditional expression expr and return a status of 0
(true) or 1 (false). Each operator and operand must be a separate
argument. Expressions are composed of the primaries described below
in Section 6.4 [Bash Conditional Expressions], page 92. test does not
accept any options, nor does it accept and ignore an argument of --
as signifying the end of options. When the [ form is used, the last
argument to the command must be a ].
-- 
http://lists.linuxfromscratch.org/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Do not top post on this list.

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

http://en.wikipedia.org/wiki/Posting_style

Reply via email to