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

Re: Bug Report: Env Vars and shell functions



aheading@xxxxxxxxxxxx wrote:
> On a related note, should the following not restore IFS?
> 
> sun4% IFS=@ set a@b@c@d; echo $IFS 
> @

This is a very ancient, revered and traditional bug, handed down since
time immemorial from the hand of pfalstad himself.  Special parameters
aren't restored after builtin constructs, unlike other parameters (at
least, after Zoltan's recent patches).  The problem is that there are
numerous different ways for setting builtins, and to do this properly
would mean save/restore functions for each.

One hack (actually, that's unfair --- I've used more or less the same
trick in a C++ parameter-reading class with templated virtual
functions, relying only on the presence of insertors and extractors
for the type in question, and it works vey nicely) that might work
here with a lot of parameters (but not such as SECONDS, which would
really need its own functions) is to retrieve the parameter as a
string value with the function used with $VAR for printing,
getstrvalue(), store that, then call the function that sets the
parameter from a string supplied on the command line with VAR=...,
setsparam().  This would do the trick reasonably simply for things
like PATH and IFS.  Probably care is needed, e.g. you can forget this
for arrays and what do you do if someone tries it with $path or
$cdpath?  Any comments?  Any implementations???

> And finally, why doesn't this work?
> sun4% local x=($(date))
> zsh: not an identifier: 10 BST 1996)

Do you mean, why can't you assign arrays from `local'?  I don't see any
prospect of doing it like that, since you would need special parsing
of the stuff in parentheses, which is somewhat abhorrent for something
that's supposed to look like an ordinary command; passing the argument
as a single word gets you into problems of how to split it later ---
and in the case shown, you still need special parsing to avoid getting
the expansion
     local x=Fri Jul 12 14:12:47 MET 1996
with fully-paid-up spaces between the arguments, which is what is
currently (and correctly) happening.  (Csh does special parsing after
`set', 'nuff said).  It should, however, definitely be possible to do
the equivalent of `set -A' with local or typeset, but it isn't.  This
is very nearly a bug.

Actually, I don't quite understand that error message, since it
suggests the last few words are passed as one, which isn't happening
to me.

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.




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