diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2013-08-23 21:27:42 +1000 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2020-03-28 21:42:54 +0000 |
commit | 285328db698e018ef91c9f04f59f25e3133d0984 (patch) | |
tree | f11dd19e39fda8b4e29665fe809708709d46af65 | |
parent | cd3104d4d44a7723a93c2c316ea60a2d6ab83677 (diff) | |
download | klibc-285328db698e018ef91c9f04f59f25e3133d0984.tar.gz |
[klibc] dash: [VAR] Initialise OPTIND after importing environment
[ dash commit a14c418aee9d4ccd7cf888024e318b300173099f ]
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>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | usr/dash/var.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/usr/dash/var.c b/usr/dash/var.c index c35e925ee86dac..fa248544bccf28 100644 --- a/usr/dash/var.c +++ b/usr/dash/var.c @@ -142,6 +142,8 @@ INIT { } } + setvarint("OPTIND", 1, 0); + fmtstr(ppid + 5, sizeof(ppid) - 5, "%ld", (long) getppid()); setvareq(ppid, VTEXTFIXED); |