Hi,

I'm trying to understand bash's parsing model.

I read in the manual that the shell "breaks the input into words and operators,
obeying the quoting rules described in Quoting. These tokens are separated by
metacharacters."

Taking this simple example:

[...@host ~] $ echo The date is $(date +'%Y-%m-%d')
2010-02-23

Breaking this into words, using the above rule, results in:

-------     -------------
echo        word
<space>     metacharacter
The         word
<space>     metacharacter
date        word
<space>     metacharacter
is          word
<space>     metacharacter
$           word
(           metacharacter
date        word
<space>     metacharacter
+'%Y-%m-%d' word
)           metacharacter

This confuses me because, intuitively, I feel that the command substitution,
$(date +'%Y-%m-%d'), should be treated as a single word.

Indeed, the manual later says "The words that are not variable assignments or
redirections are expanded (see Shell Expansions)." This suggests to me that a
command substitution, indeed all expansions, should be treated as a single word.

Can someone elucidate how bash breaks the input into words?

Thank you,

Allen Halsey



Reply via email to