summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2005-05-16 04:32:41 +0000
committergad <gad@FreeBSD.org>2005-05-16 04:32:41 +0000
commit2577be22134873f1d6d4ee3102a1ce80c32bcb5d (patch)
tree0ace0d6f355638f5e9082f2d0c7ee794246fe12f /bin
parent449a09d7f46bf7fcc99e7d6de94aed98659279f6 (diff)
downloadFreeBSD-src-2577be22134873f1d6d4ee3102a1ce80c32bcb5d.zip
FreeBSD-src-2577be22134873f1d6d4ee3102a1ce80c32bcb5d.tar.gz
A second attempt to adjust option-parsing on a shell command, for the
benefit of scripts start out as: #!/bin/sh -- # -*- perl -*- With this fix in place, we can commit a change to kern/imgact_shell.c so FreeBSD will process the `#!' line in shell-scripts in a more standard fashion. PR: 16393 Mentioned on: freebsd-arch
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/options.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/bin/sh/options.c b/bin/sh/options.c
index bc60a96..d2c4a98 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -138,7 +138,7 @@ optschanged(void)
STATIC void
options(int cmdline)
{
- char *p;
+ char *kp, *p;
int val;
int c;
@@ -153,6 +153,25 @@ options(int cmdline)
goto end_options1;
if (p[0] == '-' && p[1] == '\0')
goto end_options2;
+ /**
+ * For the benefit of `#!' lines in shell scripts,
+ * treat a string of '-- *#.*' the same as '--'.
+ * This is needed so that a script starting with:
+ * #!/bin/sh -- # -*- perl -*-
+ * will continue to work after a change is made to
+ * kern/imgact_shell.c to NOT token-ize the options
+ * specified on a '#!' line. A bit of a kludge,
+ * but that trick is recommended in documentation
+ * for some scripting languages, and we might as
+ * well continue to support it.
+ */
+ if (p[0] == '-') {
+ kp = p + 1;
+ while (*kp == ' ' || *kp == '\t')
+ kp++;
+ if (*kp == '#' || *kp == '\0')
+ goto end_options2;
+ }
} else if (c == '+') {
val = 0;
} else {
OpenPOWER on IntegriCloud