* OPTIND
@ 2013-03-23 1:46 Chris F.A. Johnson
2013-08-23 11:28 ` OPTIND Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Chris F.A. Johnson @ 2013-03-23 1:46 UTC (permalink / raw)
To: dash
According to both the dash man page and the POSIX spec, "When the
shell is invoked, OPTIND is initialized to 1."
However, it actually takes the value of the environment variable
if it exists:
$ OPTIND=4 dash -c 'echo "$OPTIND"'
4
$ OPTIND=4 bash -c 'echo "$OPTIND"'
1
$ OPTIND=4 ksh -c 'echo "$OPTIND"'
1
$ OPTIND=4 ksh93 -c 'echo "$OPTIND"'
1
--
Chris F.A. Johnson, <http://cfajohnson.com/>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: OPTIND
2013-03-23 1:46 OPTIND Chris F.A. Johnson
@ 2013-08-23 11:28 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2013-08-23 11:28 UTC (permalink / raw)
To: Chris F.A. Johnson; +Cc: dash
commit a14c418aee9d4ccd7cf888024e318b300173099f
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date: Fri Aug 23 21:27:42 2013 +1000
[VAR] Initialise OPTIND after importing environment
On Sat, Mar 23, 2013 at 01:46:20AM +0000, Chris F.A. Johnson wrote:
>
> According to both the dash man page and the POSIX spec, "When the
> shell is invoked, OPTIND is initialized to 1."
>
> However, it actually takes the value of the environment variable
> if it exists:
>
> $ OPTIND=4 dash -c 'echo "$OPTIND"'
> 4
> $ OPTIND=4 bash -c 'echo "$OPTIND"'
> 1
> $ OPTIND=4 ksh -c 'echo "$OPTIND"'
> 1
> $ OPTIND=4 ksh93 -c 'echo "$OPTIND"'
> 1
This patch fixes this by initialising OPTIND after importing the
environment.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/ChangeLog b/ChangeLog
index 9500c87..4276676 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
2013-08-23 Herbert Xu <herbert@gondor.apana.org.au>
* Propagate EXP_QPAT in subevalvar.
+ * Initialise OPTIND after importing environment.
2013-03-12 Peter Rosin <peda@lysator.liu.se>
diff --git a/src/var.c b/src/var.c
index c35e925..fa24854 100644
--- a/src/var.c
+++ b/src/var.c
@@ -142,6 +142,8 @@ INIT {
}
}
+ setvarint("OPTIND", 1, 0);
+
fmtstr(ppid + 5, sizeof(ppid) - 5, "%ld", (long) getppid());
setvareq(ppid, VTEXTFIXED);
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-08-23 11:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-23 1:46 OPTIND Chris F.A. Johnson
2013-08-23 11:28 ` OPTIND Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.