According to Allen Halsey on 2/23/2010 3:50 PM: > 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."
Another good reference is POSIX: http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_03 > 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 So far, so good. But you missed that: $(date +'%Y-%m-%d') is an entire word (basically, an unquoted $ character consumes until the end of the shell substitution, command substitution, or arithmetic substitution, and that entire scan becomes part of the current word being parsed). > This confuses me because, intuitively, I feel that the command substitution, > $(date +'%Y-%m-%d'), should be treated as a single word. Yes, it is a single word. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature