zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: emulate -L sh impact on $0, $argv
Date: Sun, 31 Jan 2016 12:37:45 -0800	[thread overview]
Message-ID: <160131123745.ZM12069@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVCWzg0n352x9HSzLm9Q4CxBQVvruUb0YbYt2ERVbmCOwA@mail.gmail.com>

On Jan 31,  8:13pm, Sebastian Gniazdowski wrote:
}
} In sh argv[0] is the same as argv[1]? Because again, you say I
} shouldn't be able to use argv[0] without KSH_ARRAYS, but in the
} examples, I do

This is a side-effect KSH_ARRAYS combined with the behavior of
$argv / $* / $@ when in the "source" command.  Doc of "." command:

     If any arguments ARG are given, they become the positional
     parameters; the old positional parameters are restored when the
     FILE is done executing.

What's left unsaid there is that if NO arguments are given, then the
positional parameters REMAIN THOSE OF THE CALLING CONTEXT.  So argv[0]
in your example is not test_file.sh's $0, it's the "source" FUNCTION's
$argv[1].

If you change your example to:

echo 'echo 0 is $0, argv0 is ${argv[0]}, argv1 is ${argv[1]}' > test_file.sh;
source ./test_file.sh ARGUMENT

Then the zsh case

    source() { emulate -L zsh; builtin source "$@"; }

will give

    0 is ./test_file.sh, argv0 is , argv1 is ARGUMENT

whereas the sh case

    source() { emulate -L sh; builtin source "$@"; }

yields

    0 is source, argv0 is ARGUMENT, argv1 is 

With KSH_ARRAYS set, $argv[0] == $1, $argv[1] == $2, etc.


  parent reply	other threads:[~2016-01-31 20:36 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)
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 [this message]
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=160131123745.ZM12069@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).