zsh-workers
 help / color / mirror / code / Atom feed
* POSIX_ARGZERO: not POSIX compliant in sourced script?!
@ 2014-09-11 20:07 Daniel Hahler
  2014-09-12  3:59 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Hahler @ 2014-09-11 20:07 UTC (permalink / raw)
  To: Zsh Hackers' List

The option POSIX_ARGZERO (added in 19f3161 for zsh 5.0.5) does not appear to be fully POSIX compliant when being used in a sourced file.

I don't know how POSIX defines it, but at least dash (and bash) behave differently.

Given the following files:

cat > test.sh <<EOF
#!/bin/sh
. ./test_sourced.sh
EOF


cat > test_sourced.sh <<EOF
echo $0

if [ -n "$ZSH_VERSION" ]; then
  setopt posixargzero
  echo $0
fi
EOF


The second $0 with zsh should be "test.sh", and not "zsh":

% zsh test.sh
test_sourced.sh
zsh

% sh test.sh
test.sh
test.sh

% ./test.sh
./test.sh


The same applies when using zsh in the shebang line, and executing the script (I was under the impression that this would work better, but it does not):

cat > test.sh <<EOF
#!/usr/bin/env zsh
. ./test_sourced.sh
EOF

% ./test.sh
test_sourced.sh
zsh


Regards,
Daniel.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: POSIX_ARGZERO: not POSIX compliant in sourced script?!
  2014-09-11 20:07 POSIX_ARGZERO: not POSIX compliant in sourced script?! Daniel Hahler
@ 2014-09-12  3:59 ` Bart Schaefer
  2014-09-14  1:03   ` Daniel Hahler
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-09-12  3:59 UTC (permalink / raw)
  To: Daniel Hahler, Zsh Hackers' List

On Sep 11, 10:07pm, Daniel Hahler wrote:
}
} The option POSIX_ARGZERO (added in 19f3161 for zsh 5.0.5) does not
} appear to be fully POSIX compliant when being used in a sourced file.

Hrm.  Well, it was implemented the way it was described to us, but it
seems we need the following instead?


diff --git a/Src/init.c b/Src/init.c
index 5e92f59..d536978 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -252,8 +252,9 @@ parseargs(char **argv, char **runscript)
     paramlist = znewlinklist();
     if (*argv) {
 	if (unset(SHINSTDIN)) {
+	    posixzero = *argv;
 	    if (cmd)
-		argzero = posixzero = *argv;
+		argzero = *argv;
 	    else
 		*runscript = *argv;
 	    opts[INTERACTIVE] &= 1;

-- 
Barton E. Schaefer


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: POSIX_ARGZERO: not POSIX compliant in sourced script?!
  2014-09-12  3:59 ` Bart Schaefer
@ 2014-09-14  1:03   ` Daniel Hahler
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Hahler @ 2014-09-14  1:03 UTC (permalink / raw)
  To: Zsh Hackers' List

Thanks for fixing this!

(Reference: Git commit 03e53c8)


Regards,
Daniel.

On 12.09.2014 05:59, Bart Schaefer wrote:
> On Sep 11, 10:07pm, Daniel Hahler wrote:
> }
> } The option POSIX_ARGZERO (added in 19f3161 for zsh 5.0.5) does not
> } appear to be fully POSIX compliant when being used in a sourced file.
> 
> Hrm.  Well, it was implemented the way it was described to us, but it
> seems we need the following instead?
> 
> 
> diff --git a/Src/init.c b/Src/init.c
> index 5e92f59..d536978 100644
> --- a/Src/init.c
> +++ b/Src/init.c
> @@ -252,8 +252,9 @@ parseargs(char **argv, char **runscript)
>      paramlist = znewlinklist();
>      if (*argv) {
>  	if (unset(SHINSTDIN)) {
> +	    posixzero = *argv;
>  	    if (cmd)
> -		argzero = posixzero = *argv;
> +		argzero = *argv;
>  	    else
>  		*runscript = *argv;
>  	    opts[INTERACTIVE] &= 1;
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-14  1:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11 20:07 POSIX_ARGZERO: not POSIX compliant in sourced script?! Daniel Hahler
2014-09-12  3:59 ` Bart Schaefer
2014-09-14  1:03   ` Daniel Hahler

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