[klibc] [klibc:update-dash] [VAR] Initialise OPTIND after importing environment
klibc-bot for Herbert Xu
herbert at gondor.apana.org.au
Thu Jan 24 19:15:11 PST 2019
Commit-ID: d91eb7955d736009945a0c8418a07d6b28df020f
Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=d91eb7955d736009945a0c8418a07d6b28df020f
Author: Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Fri, 23 Aug 2013 21:27:42 +1000
Committer: Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000
[klibc] [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 at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
---
usr/dash/var.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/usr/dash/var.c b/usr/dash/var.c
index c35e925e..fa248544 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);
More information about the klibc
mailing list