help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Separation of compound commands


From: Andy Chu
Subject: Re: [Help-bash] Separation of compound commands
Date: Tue, 14 Mar 2017 10:28:08 -0700

Yes, the statements in (A) are strictly POSIX -- { } and ().  As far as I
can tell, the lack of semi-colons follows from the POSIX grammar:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10

(B) are bash extensions, I think borrowed from ksh.  However I think
there's no reason that shouldn't work if [[ and (( are parsed in the same
place as if/for/etc.

I tested my OSH parser and they both work fine.

$ bin/osh --ast-output - -c '{ [[ 1 ]] }'
(BraceGroup children:[(DBracket expr:(WordTest w:{(1)}))] spids:[0])

$ bin/osh --ast-output - -c '{ (( 1 )) }'
(BraceGroup children:[(DParen child:(ArithWord w:{(Lit_Digits 1)}))]
spids:[0])

(Although (()) doesn't work, (( 1 )) works.  I didn't really think about
it, but (( )) has to be non-empty in my parser.)

Andy




On Tue, Mar 14, 2017 at 9:42 AM, Nicholas Chambers <
address@hidden> wrote:

>
>
> On 3/14/17 11:24 AM, D630 wrote:
>
>> Why does A work, but B doesn't?
>>
>> # A
>> { { :; } }
>> if :; then if :; then :; fi fi
>> { (:) }
>>
>
> Braces can be nested, however statements/commands need to be terminated.
> That is why the first works. I am not sure what part you don't understand
> in the second example. For the third, bash can tell that the statement : is
> over since it is wrapped in ()'s. If it didn't have those you would need a
> semicolon again (ie { :; }).
>
>
>> # B
>> { (()) }
>> { [[ 1 ]] }
>>
>>
>>
> (()) is a very different kind of statement than (:). (()) is for math. {
> (()); } works. { ( (()) ) } works. { (( 3 + 4 )); } works. Same with [[ 1
> ]]. It is a statement, so it needs some kind of delimiter for bash to say
> its finished. Again, { ( [[ 1 ]] ) } works, and { [[ 1 ]]; } works.
>
> --
> Nicholas Chambers
> Technical Support Specialist
> address@hidden
> 1.800.444.9267
> www.lightspeedsystems.com
>
>
>


reply via email to

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