On Tue, Mar 18, 2008 at 01:11:35AM +0800, [EMAIL PROTECTED] wrote: > On the man page at section "export", mention that the latter below > will not do what one expects, as here revealed: > $ set -x > $ a=1 b=$a > + a=1 > + b=1 > $ export x=1 y=$x > + export x=1 y= > + x=1 > + y= > Yes I'm sure it is mentioned elsewhere on the page but you might want > to drum it home again here. Maybe also at $ help export. [...]
Yes, "export" and the "typeset/local/integer"... family of commands is a bit confusing, and the behavior varies a lot between shells. In ksh, they behave more like an assignment qualifier (in terms of how the command line is parsed) (though not completely as in export $vars) In zsh and ash, they behave like a normal built in. In bash, it's a bit inbetween. I think the POSIX spec as it is written now would say that zsh and ash are correct. In ksh, a="b c" export d=$a $d exports the d variable with value "b c" and the b and c variables. Because d=$a is treated as a variable assignment. in ash/zsh (in sh emulation) exports the d variable with value b and the c variable. because, it's a simple command line parsed like a simple command line with word splitting et all and it's the "export" command that performs the assignment. in bash exports the d variable with value "b c" and that's it. Typically, my advice would be to avoid the export var=value syntax and to prefer: var=value export var Which is more portable (even to the Bourne shell!), and you know where you stand. -- Stéphane