[Pkg-zsh-devel] Bug#691886: Bug#691886: zsh: ". file" in .zshenv gets arguments from the original script

Axel Beckert abe at debian.org
Tue Oct 30 18:21:03 UTC 2012


Hi Vincent,

Vincent Lefevre wrote:
> Consider a script "script1" containing only the following line:
> 
> #!/usr/bin/env zsh
> 
> and a script "script2" containing:
> 
> echo Args: "$@"
> 
> The .zshenv file contains:
> 
> . ~/script2
> . ~/script2 blah
> 
> I get the following:
> 
> xvii% ./script1 ab cd ef
> Args: ab cd ef
> Args: blah

Looks as expected for me.

> The first line shouldn't show any argument because an empty list of
> positional parameters was provided in the ". ~/script2" line!

I think that's wrong.

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.

		Regards, Axel
-- 
 ,''`.  |  Axel Beckert <abe at debian.org>, http://people.debian.org/~abe/
: :' :  |  Debian Developer, ftp.ch.debian.org Admin
`. `'   |  1024D: F067 EA27 26B9 C3FC 1486  202E C09E 1D89 9593 0EDE
  `-    |  4096R: 2517 B724 C5F6 CA99 5329  6E61 2FF9 CD59 6126 16B5



More information about the Pkg-zsh-devel mailing list