Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
POSIX_ARGZERO: not POSIX compliant in sourced script?!
- X-seq: zsh-workers 33142
- From: Daniel Hahler <dhahler@xxxxxxxxx>
- To: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Subject: POSIX_ARGZERO: not POSIX compliant in sourced script?!
- Date: Thu, 11 Sep 2014 22:07:28 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:message-id:date:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=1f49GDm6pl3C786tVBLM8+pHLwsY6d8bK7hids9Mo2M=; b=A+SJMtzu1OWlfPD1eevSMu5ulbPKSygZBULoyUHQdnTNu7GnmvkqdNR3xxNlTeGl76 WO11nRZsScayy89HONSm3VImz7nTsLbg4jatM+z9splglWSG9mAaIJN18cKVkUl6GiVO ar90Jd8UHxN1PEi8qKQqH4u9Fe881XRApm1A+wl4JKe0qSQqR47TK0bRur/2TfpcYmW3 EwCG4uwjprTKWV5Z+qFyWVJdPd0BFs2TRdTO1v8mDZGq3bRxwcqAMl66eY2/wn90f/Oc RgadlQqspljXtnaJ/CvNiCkEktSwWPB/w4WQW2IPSIzSgG8Cf54wtmmuOCNhtIlIDq4R 8tCg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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