[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parsing, metacharacters, tokens.
From: |
Greg Wooledge |
Subject: |
Re: Parsing, metacharacters, tokens. |
Date: |
Thu, 19 May 2022 07:13:41 -0400 |
On Thu, May 19, 2022 at 12:32:59PM +0200, Cristian Zoicas wrote:
> There are situations when it is not clear from the manual how bash
> performs expansions/splitting/substitutions.
Yeah. Bash syntax is a nightmare.
> According to what is written in the manual a metacharacter is:
>
> A character that, when unquoted, separates words. A metacharacter
> is one of the following characters:
> <space> <tab> <newline> | & ; ( ) < >
>
> Now let's assume the following statement:
>
> A=START$(echo _)END
>
> According to the definition of metacharacters the first token would be
> "A=START$" (because '(' separates tokens) and then will follow the rest of
> the tokens .
You're reading the quoted sentences far too literally, or else you're
adding some of your own assumptions to it. I'm not sure which.
( is a metacharacter, but not when it's preceded by $. There are various
combinations of characters that act like a single character, as far as
parsing goes. $( is the introduction of a command substition, and it
doesn't cause a word separation the way that ( does.
Similarly, <& and >& act like a single metacharacter, not two different
metacharacters back to back.
In your example, START$(echo _)END is all one word. The $(...) bit
will undergo a command substitution. Then, because the word is on the
right hand side of a simple assignment, there WON'T be an additional
word-splitting round, despite the lack of explicit double quotes.