zsh-workers
 help / color / mirror / code / Atom feed
* $0 (or argv[0]) not used in error messages in zsh -c inlinescripts
@ 2022-09-20 13:18 Stephane Chazelas
  2022-09-20 23:35 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Chazelas @ 2022-09-20 13:18 UTC (permalink / raw)
  To: Zsh hackers list

(minor)

$ zsh -uc 'echo $0; :>/; 0=foo; $1' myinlinescript
myinlinescript
zsh:1: is a directory: /
zsh:1: 1: parameter not set

I expected:

myinlinescript
myinlinescript:1: is a directory: /
foo:1: 1: parameter not set

Like most other Bourne-like shells (except yash) do (except for the assignment
to $0 which none other supports).

Isn't it the whole point of being able to specify $0, so it's
treated as the script's name when using zsh -c?

Note that the interpreter's argv[0] is always ignored in any case.

$ ARGV0=foo zsh -uc 'echo $0; :>/; $1'
foo
zsh:1: is a directory: /
zsh:1: 1: parameter not set

Also applies to:

$ ARGV0=foo zsh -u <<< 'echo $0; :>/; 0=bar; $1'
foo
zsh: is a directory: /
zsh: 1: parameter not set

Modifications to $0 are honoured in:

$ zsh <(<<<'echo "$0"; :>/; 0=foo; :>/')
/proc/self/fd/11
/proc/self/fd/11:1: is a directory: /
foo:1: is a directory: /

Not in:

$ zsh -c '. $1' foobar =(<<<'echo $0; :>/; 0=foo; :>/')
/tmp/zshl53EOM
/tmp/zshl53EOM:1: is a directory: /
/tmp/zshl53EOM:1: is a directory: /


See also:

$ zsh -c 'f() { echo $0; :>/; 0=foo; :>/; }; f'
f
f: is a directory: /
f: is a directory: /


(modified $0 not used in error message).

-- 
Stephane


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

end of thread, other threads:[~2022-09-20 23:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 13:18 $0 (or argv[0]) not used in error messages in zsh -c inlinescripts Stephane Chazelas
2022-09-20 23:35 ` 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).