zsh-workers
 help / color / mirror / code / Atom feed
From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@yandex.ru>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: emulate -L sh impact on $0, $argv
Date: Sun, 31 Jan 2016 21:12:07 +0300	[thread overview]
Message-ID: <7850171454263927@web30j.yandex.ru> (raw)
In-Reply-To: <CAKc7PVDMSiWckCwSijk8i6js86OCNeRuwfkVV1xjGMv_W554_Q@mail.gmail.com>



31.01.2016, 21:04, "Sebastian Gniazdowski" <sgniazdowski@gmail.com>:
> Hello
> Is this expected behavior:
>
> % echo 'echo Hello, my 0 is $0, argv0 is ${argv[0]}' > test_file.sh;
> source() { emulate -L zsh; builtin source "$@"; }; source
> ./test_file.sh
> Hello, my 0 is ./test_file.sh, argv0 is
>
> % echo 'echo Hello, my 0 is $0, argv0 is ${argv[0]}' > test_file.sh;
> source() { emulate -L sh; builtin source "$@"; }; source
> ./test_file.sh
> Hello, my 0 is source, argv0 is ./test_file.sh
>
> Sometimes -L zsh gives correct argv[0], couldn't clarify exactly when,
> it may have something to do with reversed order of the calls.

Array indexing starts with one, not zero, so $argv[0] in zsh emulation mode is not what you think: it is empty. *Always*. And in any case has nothing to do with $0, $0 is never present in $argv. Array indexing *may* start with zero, controlled by KSH_ARRAYS option which is again different in zsh and sh emulation mode.

What is contained is $0 is controlled by FUNCTION_ARGZERO option, which is different in zsh and sh modes.

>
> Best regards,
> Sebastian Gniazdowski


  reply	other threads:[~2016-01-31 18:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-31 18:03 Sebastian Gniazdowski
2016-01-31 18:12 ` Nikolay Aleksandrovich Pavlov (ZyX) [this message]
2016-01-31 18:43   ` Bart Schaefer
2016-01-31 19:13   ` Sebastian Gniazdowski
2016-01-31 20:04     ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-01-31 20:37     ` Bart Schaefer
2016-02-07  0:22       ` Daniel Shahaf

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=7850171454263927@web30j.yandex.ru \
    --to=kp-pav@yandex.ru \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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