From 01c7bd5378252005aa3f9ccdaa5bcaf978be9039 Mon Sep 17 00:00:00 2001 From: Garance A Drosehn Date: Mon, 16 May 2005 04:32:41 +0000 Subject: [PATCH] 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 --- bin/sh/options.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/sh/options.c b/bin/sh/options.c index bc60a96f4e32..d2c4a982cf49 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 {