On Sat, Mar 07, 2015 at 07:16:53AM +0100, Sébastien Marie wrote:
> Hi,
>
> I encounter a problem of parsing in ksh(1): a quote in a comment in a
> command substitution $(...) or `...` is parsed as quote and a closing quote
> is expected.
>
> Here code snippet that expose the problem:
>
> $ cat test.sh
> echo $(echo abc |
> # comment
> cat)
>
> echo $(echo abc |
> # comment with quote '
> cat)
>
> $ ksh ./test.sh
> abc
> ./test.sh[9]: no closing quote
>
>
> As side note, bash(1) don't have this parsing problem.
>
> $ bash ./test.sh
> abc
> abc
> $
>
> Thanks.
Here a patch to address this problem.
It just adds comment stripping in $(...) parsing.
I think the patch need good review: I haven't tested it deeply.
Thanks.
--
Sébastien Marie
Index: lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.49
diff -u -p -r1.49 lex.c
--- lex.c 17 Dec 2013 16:37:06 -0000 1.49
+++ lex.c 9 Mar 2015 05:18:19 -0000
@@ -475,6 +475,12 @@ yylex(int cf)
statep->ls_scsparen.csstate = 4;
ignore_backslash_newline++;
break;
+ case '#':
+ ignore_backslash_newline++;
+ while ((c = getsc()) != '\0' && c !=
'\n')
+ ;
+ ignore_backslash_newline--;
+ ungetsc(c);
}
break;