From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14062 invoked by alias); 7 Feb 2016 00:28:53 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37896 Received: (qmail 22931 invoked from network); 7 Feb 2016 00:28:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 Date: Sun, 07 Feb 2016 00:22:10 +0000 From: Daniel Shahaf To: Zsh hackers list Subject: Re: emulate -L sh impact on $0, $argv Message-ID: <20160207002210.GA24068@tarsus.local2> References: <7850171454263927@web30j.yandex.ru> <160131123745.ZM12069@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <160131123745.ZM12069@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) Bart Schaefer wrote on Sun, Jan 31, 2016 at 12:37:45 -0800: > 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]. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 542cecf..5aebdef 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -81,6 +81,10 @@ then commands are read from that file instead of var(file). If any arguments var(arg) are given, they become the positional parameters; the old positional parameters are restored when the var(file) is done executing. +However, if no arguments are given, +the positional parameters remain those of the calling context, +and no restoring is done. + If var(file) was not found the return status is 127; if var(file) was found but contained a syntax error the return status is 126; else the return status is the exit status of the last command executed.