Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh handling of non-standard if-evaluations
- X-seq: zsh-users 11168
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Daniel Qarras <dqarras@xxxxxxxxx>
- Subject: Re: zsh handling of non-standard if-evaluations
- Date: Wed, 31 Jan 2007 21:03:46 +0000
- Cc: Zsh Users List <zsh-users@xxxxxxxxxx>
- In-reply-to: <388703.9886.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Daniel Qarras <dqarras@xxxxxxxxx>, Zsh Users List <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20070131172324.GA9255@xxxxxxxxxxxxxxx> <388703.9886.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Sender: Stephane Chazelas <stephane_chazelas@xxxxxxxx>
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