* $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
* Re: $0 (or argv[0]) not used in error messages in zsh -c inlinescripts
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
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-09-20 23:35 UTC (permalink / raw)
To: Zsh hackers list
I believe that comes down to this bit of code in zwarning() (utils.c):
char *prefix = scriptname ? scriptname : (argzero ? argzero : "");
...
/*
* scriptname is set when sourcing scripts, so that we get the
* correct name instead of the generic name of whatever
* program/script is running. It's also set in shell functions,
* so test locallevel, too.
*/
nicezputs((isset(SHINSTDIN) && !locallevel) ? "zsh" : prefix, stderr);
In parseopts() (init.c) for the -c option there is:
if (toplevel)
scriptname = scriptfilename = ztrdup("zsh");
So because scriptname is always preferred and at toplevel is always
set, you get the observed behavior.
This is all pretty tangled up with POSIX_ARGZERO as well, so I'm not
certain of the correct fix.
^ 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).