From a14c418aee9d4ccd7cf888024e318b300173099f Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Fri, 23 Aug 2013 21:27:42 +1000 Subject: [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 --- ChangeLog | 1 + src/var.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9500c87..4276676 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2013-08-23 Herbert Xu * Propagate EXP_QPAT in subevalvar. + * Initialise OPTIND after importing environment. 2013-03-12 Peter Rosin 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); -- cgit 1.4.1