[Pkg-zsh-devel] Bug#691886: Bug#691886: zsh: ". file" in .zshenv gets arguments from the original script
Vincent Lefevre
vincent at vinc17.net
Tue Oct 30 23:35:39 UTC 2012
On 2012-10-30 19:21:03 +0100, Axel Beckert wrote:
> Sourced scripts are no subshells and hence inherit all variables from
> the script which sources it, including but not limited to $@, $*, $0,
> $1, $2, etc. And I'm sure there are tons of scripts which rely on this
> feature.
>
> The second sourcing of script2 just overrides $@ and friends.
This can give a surprining behavior. For instance:
#!/usr/bin/env zsh
. ~/script2 "$@[2,-1]"
One would normally expect that script2 gets the arguments with the
first one removed. But if there is only one argument, script2 is
sourced with it (instead of the empty list of arguments). I think
that having two different behaviors that depend on whether the list
of arguments is empty or not is a bad interface.
There would be no such problems if one would have the possibilities
. file
to source file with $@ inherited.
. file -- [ args ]
to source file with args (possibly empty) overriding $@.
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the Pkg-zsh-devel
mailing list