zsh-workers
 help / color / mirror / code / Atom feed
* Positional parameters and sourced files
@ 2000-05-28  0:31 Bart Schaefer
  2000-05-28  9:10 ` Bernd Eggink
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2000-05-28  0:31 UTC (permalink / raw)
  To: zsh-workers

Put these commands in /tmp/test.zsh:

	echo $# $*
	set a b c d e

Now:

zsh% source /tmp/test.zsh ; echo $#
0
5
zsh% source /tmp/test.zsh arg ; echo $#
1 arg
0


So "set ..." in a sourced script changes the global positional parameters
when the script is called with no arguments, but if it was called with any
arguments then it changes only the locals.  This seems a bit odd.

Bash, on the other hand, always changes the global positional parameters,
and further it throws away the local ones when the global ones are set.  I
don't have ksh handy to try.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Positional parameters and sourced files
  2000-05-28  0:31 Positional parameters and sourced files Bart Schaefer
@ 2000-05-28  9:10 ` Bernd Eggink
  2000-05-28 17:16   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Eggink @ 2000-05-28  9:10 UTC (permalink / raw)
  To: zsh-workers

On Sun, May 28, 2000 at 12:31:10AM +0000, Bart Schaefer wrote:
> Put these commands in /tmp/test.zsh:
> 
> 	echo $# $*
> 	set a b c d e
> 
> Now:
> 
> zsh% source /tmp/test.zsh ; echo $#
> 0
> 5
> zsh% source /tmp/test.zsh arg ; echo $#
> 1 arg
> 0
> 
> 
> So "set ..." in a sourced script changes the global positional parameters
> when the script is called with no arguments, but if it was called with any
> arguments then it changes only the locals.  This seems a bit odd.
> 
> Bash, on the other hand, always changes the global positional parameters,
> and further it throws away the local ones when the global ones are set.  I
> don't have ksh handy to try.
 
ksh behaves the same way as zsh. IMHO the bash behavior is the most
reasonable one.

Regards,
Bernd

-- 
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Positional parameters and sourced files
  2000-05-28  9:10 ` Bernd Eggink
@ 2000-05-28 17:16   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2000-05-28 17:16 UTC (permalink / raw)
  To: Bernd Eggink, zsh-workers

On May 28, 11:10am, Bernd Eggink wrote:
} Subject: Re: Positional parameters and sourced files
}
} ksh behaves the same way as zsh.

That's probably -why- zsh behaves that way, then.

} IMHO the bash behavior is the most reasonable one.

I think they're both strange.  Look at what happens to zsh scripts when
you put a `set a b c d e' in /etc/zshenv.  (Bash doesn't have that problem
because it has no init scripts that are run for non-interactive shells,
but the principle is the same.)

The positionals should be local, always.  Unfortunately that probably
breaks some expectation of old Bourne shell scripts, or some such.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-05-28 17:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-28  0:31 Positional parameters and sourced files Bart Schaefer
2000-05-28  9:10 ` Bernd Eggink
2000-05-28 17:16   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).