zsh-workers
 help / color / mirror / code / Atom feed
* Re: zsh not sourcing /etc/profile?
@ 1997-04-14 19:51 Alain Caron
  1997-04-14 22:38 ` Zoltan T. Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Alain Caron @ 1997-04-14 19:51 UTC (permalink / raw)
  To: hzoli; +Cc: coleman, zsh-workers

In message "Re: zsh not sourcing /etc/profile?",
'hzoli@vnet.IBM.COM' writes:

>Richard Coleman wrote:
>> I found this article on comp.unix.shells.  I thought I would
>> pass it along.
>[...]
>> > posix-sh, ksh, and bash all return the name of the shell for $0 when
>> > sourcing a file.
>> >
>> > Only zsh returns the name of the file being sourced.  I suspect the
>> > right behaviour is to return the shell name.  The reason for this is
>> > that sourcing a file does not create a new process, it should behave
>> > as if the file had been typed from the keyboard.  If you type the
>> > command "echo $0" at the prompt, it should return the shell name.
>> > Although I really like zsh, I think it does not have the right
>> > behaviour because you can't rely on $0 to determine which shell is
>> > interpreting the file.
>
>Under zsh this is controlled by the FUNCTION_ARGZERO option, which is set
>when zsh is started as sh/ksh.
>
>Zoltan
>

Even there, the behaviour is not the same as ksh.

On HP-UX 9.05


under ksh:

1> echo $0
ksh
2> echo 'echo "$0"' > bar
3> . ./bar
ksh
4> function foo { echo $0 }
5> foo
foo

under zsh :
1> echo $ZSH_VERSION
3.0.2
2> echo $0
zsh
3> [[ -o function_argzero ]] && echo "yes" || echo "no"
yes
4> echo 'echo "$0"' >! bar
5> . ./bar
./bar
6> function foo { echo $0 }
7> foo
foo
8> unsetopt function_argzero
9> [[ -o function_argzero ]] && echo "yes" || echo "no"
no
10> . ./bar
zsh
11> foo
zsh
12> emulate ksh
13> . ./bar
zsh
14> foo
zsh

The behaviour shown by ksh seems, IMHO,  better than the one shown by
zsh.  The reason is that sourcing a file should have the same
behaviour as typing the text.  However, in a function, $0 is more
useful as the name of the function than the name of the shell.

Also, with emulate ksh, the behaviour of zsh is different than ksh.

Shouldn't we change the behaviour of function_argzero option to behave
more like ksh?

Regards,

Alain Caron
Nortel Technology, Montréal, Québec, Canada
email: alainc@nortel.ca


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

* Re: zsh not sourcing /etc/profile?
  1997-04-14 19:51 zsh not sourcing /etc/profile? Alain Caron
@ 1997-04-14 22:38 ` Zoltan T. Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan T. Hidvegi @ 1997-04-14 22:38 UTC (permalink / raw)
  To: Alain Caron; +Cc: Zsh workers list

Alain Caron wrote:
[...]
> Even there, the behaviour is not the same as ksh.
[...]
> under ksh:
> 4> function foo { echo $0 }
> 5> foo
> foo
>
> under zsh :
[...]
> 6> function foo { echo $0 }
[...]
> 12> emulate ksh
[...]
> 14> foo
> zsh

Well, POSIX requires that $0 should always be the name used to invoke the
shell.  The latest ksh claims to be POSIX conformant...  Of course it is
possible to add a new option called something like SCRIPT_ARGZERO but that
would probably just further increase the confusion.

Zoltan


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

* Re: zsh not sourcing /etc/profile?
  1997-04-14 17:42       ` Richard Coleman
@ 1997-04-14 18:45         ` Zoltan T. Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan T. Hidvegi @ 1997-04-14 18:45 UTC (permalink / raw)
  To: Richard Coleman; +Cc: zsh-workers

Richard Coleman wrote:
> I found this article on comp.unix.shells.  I thought I would
> pass it along.
[...]
> > posix-sh, ksh, and bash all return the name of the shell for $0 when
> > sourcing a file.
> >
> > Only zsh returns the name of the file being sourced.  I suspect the
> > right behaviour is to return the shell name.  The reason for this is
> > that sourcing a file does not create a new process, it should behave
> > as if the file had been typed from the keyboard.  If you type the
> > command "echo $0" at the prompt, it should return the shell name.
> > Although I really like zsh, I think it does not have the right
> > behaviour because you can't rely on $0 to determine which shell is
> > interpreting the file.

Under zsh this is controlled by the FUNCTION_ARGZERO option, which is set
when zsh is started as sh/ksh.

Zoltan


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

* Re: zsh not sourcing /etc/profile?
       [not found]     ` <5itdj0$dc0@bmtlh10.bnr.ca>
@ 1997-04-14 17:42       ` Richard Coleman
  1997-04-14 18:45         ` Zoltan T. Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Coleman @ 1997-04-14 17:42 UTC (permalink / raw)
  To: zsh-workers

I found this article on comp.unix.shells.  I thought I would
pass it along.

rc

> > I found out it does, yes. However, I did stumble upon some bash sillyness
> > now. One of the admins we have put something similar to the following in
> > /etc/profile:
> > case "$0" in
> >  -bash|-zsh)
> >        do stuff
> >        ;;
> >  ...
> > esac
> 
> > Now, bash seems to expand the $0 to '-bash', whereas zsh expands it to
> > (which I would think is the _correct_ expansion) '/etc/profile'. It's an
> > old bash version we use here (1.14.7(1)), so I assume this is fixed
> > already in newer versions.
> 
> On my system, HP-UX 9.05
> 
> posix-sh, ksh, and bash all return the name of the shell for $0 when
> sourcing a file.
> 
> Only zsh returns the name of the file being sourced.  I suspect the
> right behaviour is to return the shell name.  The reason for this is
> that sourcing a file does not create a new process, it should behave
> as if the file had been typed from the keyboard.  If you type the
> command "echo $0" at the prompt, it should return the shell name.
> Although I really like zsh, I think it does not have the right
> behaviour because you can't rely on $0 to determine which shell is
> interpreting the file.


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

end of thread, other threads:[~1997-04-14 22:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-14 19:51 zsh not sourcing /etc/profile? Alain Caron
1997-04-14 22:38 ` Zoltan T. Hidvegi
     [not found] <5ifr3t$sub@charm.il.ft.hse.nl>
     [not found] ` <risqi5.8t6.ln@sequeira.powernet.co.uk>
     [not found]   ` <5irn2i$b2p@charm.il.ft.hse.nl>
     [not found]     ` <5itdj0$dc0@bmtlh10.bnr.ca>
1997-04-14 17:42       ` Richard Coleman
1997-04-14 18:45         ` Zoltan T. Hidvegi

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).