summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-05-28 22:40:24 +0000
committerjilles <jilles@FreeBSD.org>2010-05-28 22:40:24 +0000
commitc5fcbff43a2eb7923cdded83de0b4529deba1ca1 (patch)
tree5a790475e2c817e156e002a6faead7c8f13cc265 /bin
parentbb4be30b2dbb8dae012830d33db99d965bf90222 (diff)
downloadFreeBSD-src-c5fcbff43a2eb7923cdded83de0b4529deba1ca1.zip
FreeBSD-src-c5fcbff43a2eb7923cdded83de0b4529deba1ca1.tar.gz
sh: Recognize "--" in . and exec.
Although "--" historically has not been required to be recognized for certain special builtins that do not take options in POSIX, some other implementations recognize options for them, requiring scripts to use "--" or avoid operands starting with "-". Operands starting with "-" can be avoided with eval by prepending a space, and cannot occur with break, continue, exit, return and shift as they only take numbers, nor with times as it does not take operands. With . and exec, avoiding "-" is not so easy as it may require reimplementing the PATH search; therefore the current proposal for POSIX is to require recognition of "--" for them. We continue to accept other strings starting with "-" as operands to . and exec, and also "--" if it is alone to . (which would otherwise be invalid anyway).
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/eval.c6
-rw-r--r--bin/sh/main.c10
2 files changed, 14 insertions, 2 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index a47d045..e2f66ed 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -1170,6 +1170,12 @@ truecmd(int argc __unused, char **argv __unused)
int
execcmd(int argc, char **argv)
{
+ /*
+ * Because we have historically not supported any options,
+ * only treat "--" specially.
+ */
+ if (argc > 1 && strcmp(argv[1], "--") == 0)
+ argc--, argv++;
if (argc > 1) {
struct strlist *sp;
diff --git a/bin/sh/main.c b/bin/sh/main.c
index ecbb12d..15ee9e7 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -314,14 +314,20 @@ find_dot_file(char *basename)
int
dotcmd(int argc, char **argv)
{
- char *fullname;
+ char *filename, *fullname;
if (argc < 2)
error("missing filename");
exitstatus = 0;
- fullname = find_dot_file(argv[1]);
+ /*
+ * Because we have historically not supported any options,
+ * only treat "--" specially.
+ */
+ filename = argc > 2 && strcmp(argv[1], "--") == 0 ? argv[2] : argv[1];
+
+ fullname = find_dot_file(filename);
setinputfile(fullname, 1);
commandname = fullname;
cmdloop(0);
OpenPOWER on IntegriCloud