[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: exporting variable via variable requires more quotes than normal
From: |
Chet Ramey |
Subject: |
Re: exporting variable via variable requires more quotes than normal |
Date: |
Tue, 27 Jun 2006 09:12:38 -0400 |
User-agent: |
Thunderbird 1.5.0.4 (Macintosh/20060530) |
Mike Frysinger wrote:
> is this a bug or feature ? i never know with bash :)
>
> $ echo "HI THERE" > foo
> $ export f=$(<foo)
> $ echo $f
> HI THERE
> $ export v=f
> $ export ${v}=$(<foo)
> $ echo $f
> HI
> $ export ${v}="$(<foo)"
> $ echo $f
> HI THERE
It's a feature. Since `export' and its sibling builtins essentially take
assignment statements as arguments, the parser looks for arguments to these
builtins that are valid assignment statements and arranges for them to be
expanded as if they preceded a command name. This makes these builtins
more like statements in the shell grammar, which they may end up being
someday.
This can be fooled if you try hard enough, however, as you discovered. A
word that doesn't appear to be an assignment statement is expanded as
usual.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/