Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh handling of non-standard if-evaluations



On Wed, Jan 31, 2007 at 11:37:45AM -0800, Daniel Qarras wrote:
> Hi,
> 
> I'm asking this silly question off-line..
> 
> > In anycase, there's no much point using typeset or set or
> > non-Bourne syntax in /etc/profile (though you sometimes find
> > things like export var=value which is not Bourne and interpreted
> > differently by bash/ksh/pdksh/zsh).
> 
> Do you mean that these are different:
> 
> var=value
> export val
> 
> and
> 
> export var=value
> 
> ?
> 
> I've always wondered why people use that two-line version if the
> one-line version does excatly the same thing, would this be the
> explanation?
[...]

I beleive they use the two line versions for backward
compatibility. The Bourne shell doesn't know about the one line
one which was introduced by ksh.

It's important to know that

export var=value

does two things: assign a value to a shell variable, and mark
that variable for export. Some people just think export is the
command to assign shell variable and just litter the environment
of the commands they run. You only put in the environment
variables that may be useful to commands that you *execute* or
any of the ones they may execute themselves.

But what I was thinking of is that

the "export" command  is not parsed the same by bash and zsh for
instance. Not even by AT&T ksh and pdksh.

In pdksh and zsh, it is parsed just as any other simple command
(as POSIX would seem to require)

That's why for instance.

export var=$other_var

is not correct (in sh emulation for zsh) because the expansion
of $other_var is subject to word splitting and filename
expansion, so must be quoted as in any other command:

export "var=$other_var"

While in bash or AT&T ksh, it's very unclear how it is parsed
(and same goes for their declare/typeset...), it's a bit like a
builtin command and an assignment flag at the same time.

For instance, you can do

var="a *"
export $var

and that will export the "a" variable and one variable per file
in the current directory.

you can even do

export a=(1 2)

without getting a syntax error (while echo a=(1 2) gives you
one).

var="a=A B"
export $var

will export a=A and B while

var="A B"
export a=$var
will export a='A B'

...

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author