help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: $0 (or argv[0]) not used in error messages in zsh -c inlinescripts
Date: Tue, 20 Sep 2022 14:18:51 +0100	[thread overview]
Message-ID: <20220920131851.3rc27t4cfhwxchay@chazelas.org> (raw)


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

I expected:

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'
zsh:1: is a directory: /
zsh:1: 1: parameter not set

Also applies to:

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

Modifications to $0 are honoured in:

$ zsh <(<<<'echo "$0"; :>/; 0=foo; :>/')
/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:1: is a directory: /
/tmp/zshl53EOM:1: is a directory: /

See also:

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

(modified $0 not used in error message).


             reply	other threads:[~2022-09-20 13:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 13:18 Stephane Chazelas [this message]
2022-09-20 23:35 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220920131851.3rc27t4cfhwxchay@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=zsh-workers@zsh.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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