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

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