Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

POSIX_ARGZERO: not POSIX compliant in sourced script?!



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.



Messages sorted by: Reverse Date, Date, Thread, Author