Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
	t=1454263929; bh=dhdseuyAzlu1xNSDVM0dt0ghvBAOBZd95Rd4LmAcb9k=;
	h=From:To:In-Reply-To:References:Subject:Date;
	b=VpHRkyT88wyD2fwKIG6pR2ObYZ0EIxo+KJ8NC/7nCRnRFhKDdYgHB8nikjQcjlCC7
	 nTipqV4D+CDb4SBoNqh5nbFKNjEFBgdmefLFzQrwnX0lLsSPzX9R6aFAk2f2ZihXxe
	 8HEf7lpvfMNREMfOXVkVnsQN6piFh3kxKAb1zjGs=
From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@yandex.ru>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>,
	Zsh hackers list <zsh-workers@zsh.org>
In-Reply-To: <CAKc7PVDMSiWckCwSijk8i6js86OCNeRuwfkVV1xjGMv_W554_Q@mail.gmail.com>
References: null <CAKc7PVDMSiWckCwSijk8i6js86OCNeRuwfkVV1xjGMv_W554_Q@mail.gmail.com>
Subject: Re: emulate -L sh impact on $0, $argv
MIME-Version: 1.0
Message-Id: <7850171454263927@web30j.yandex.ru>
X-Mailer: Yamail [ http://yandex.ru ] 5.0
Date: Sun, 31 Jan 2016 21:12:07 +0300
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
X-Seq: zsh-workers 37850



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

