bug-bash
[Top][All Lists]
Advanced

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

Confused about how bash breaks input into words


From: Allen Halsey
Subject: Confused about how bash breaks input into words
Date: Tue, 23 Feb 2010 22:50:10 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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:

[me@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

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