Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
$0 (or argv[0]) not used in error messages in zsh -c inlinescripts
- X-seq: zsh-workers 50652
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: $0 (or argv[0]) not used in error messages in zsh -c inlinescripts
- Date: Tue, 20 Sep 2022 14:18:51 +0100
- Archived-at: <https://zsh.org/workers/50652>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
(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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author