Alexandru <
alexandr...@meshparts.de> wrote:
> Am Mittwoch, 14. Februar 2018 08:09:17 UTC+1 schrieb Harald Oehlmann:
>> Am 14.02.2018 um 07:54 schrieb Alexandru:
>> > Above statement seems to be true but unecpected to me. Why?
>> >
>> > (bin) 5 % puts {[expr 1+1]}
>> > [expr 1+1]
>> > (bin) 6 % puts "{[expr 1+1]}"
>> > {2}
>> >
>> > Thanks.
>> > Alexandru
>> >
>> Hello Alexandru,
>>
>> In the first case, the curly braces (gelockten Klammern) are variable
>> separators.
>> In the second case, they are data with no special meaning, as they don't
>> "embrace a word". The braces only have a special meaning if there is a
>> space-type character before and after.
>>
>> See magic Dodekalogue
>>
http://wiki.tcl.tk/10259
>>
>> Does this makes sense ?
>>
>> Thank you,
>> Harald
>
> So the clou ist that curly braces need white spaces before and after...
No, the requirement is stated in the "Tcl" manpage:
[6] Braces.
If the first character of a word is an open brace ("{") and rule
[5] does not apply,
Where 'word' is defined by rule 3 in the same man page:
[3] Words.
Words of a command are separated by white space (except
for newlines, which are command separators).
As well, rule 5 is the {*} rule.
So, in order for an open brace to be handled as a brace, it must be the
first character at the start of a word. Only then does it take on its
"brace" meaning.
In your example with the double quotes, the "word" begins with a double
quote, so rule 6 does not apply.
> Well, it's not making more sense than before since I can't imagine
> the reason for this rule, but it's enough as an explanation. I mean,
> normally, the double quotes never changed the meaning of what's
> inside them. Everything is evaluated as it is between double quotes.
The quote rule is:
[4] Double quotes.
If the first character of a word is double-quote (""") then the
word is terminated by the next double-quote character. If
semi-colons, close brackets, or white space characters (including
newlines) appear between the quotes then they are treated as
ordinary characters and included in the word. Command
substitution, variable substitution, and backslash substitution are
performed on the characters between the quotes as described below.
The double-quotes are not retained as part of the word.
So in your double quote example, your 'word' began with double quote,
so rule 4 applied, and rule 6 (braces) was never considered by the
parser.
And, in your example, the double quote rule worked as defined, because
"command substitution" occurred (the [expr 1+1] command substitution
was performed).