bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash-4.0 regression with comments in subshelled case


From: Chet Ramey
Subject: Re: bash-4.0 regression with comments in subshelled case
Date: Tue, 03 Mar 2009 17:14:16 -0500
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

Mike Frysinger wrote:
> On Tuesday 03 March 2009 15:28:28 Chet Ramey wrote:
>> Mike Frysinger wrote:
>>> code that uses case statements in a subshell and then uses comments
>>> causes bash to trigger a parsing error:
>>> $ cat test.sh
>>> echo $(case a in (a) echo ok ;; # comment
>>> )
>>> $ sh ./test.sh
>>> ./test.sh: line 1: unexpected EOF while looking for matching `)'
>>> ./test.sh: line 3: syntax error: unexpected end of file
>> As well it should.  Bash parses the contents of command substitutions, so
>> it will look forever for the missing `esac'.  The error message could be
>> improved.
> 
> sorry, the test case in the e-mail had a typo and didnt match the test case i 
> was actually using.  the 2nd line should clearly be "esac)"

In that case, try the attached patch.  And note that you don't have to
use extra left parens around the pattern lists.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.0/parse.y 2009-01-08 08:29:12.000000000 -0500
--- parse.y     2009-03-03 16:58:50.000000000 -0500
***************
*** 3172,3175 ****
--- 3179,3187 ----
  }
  
+ /* Not exactly right yet, should handle shell metacharacters, too.  If
+    any changes are made to this test, make analogous changes to subst.c:
+    extract_delimited_string(). */
+ #define COMMENT_BEGIN(x)      ((x) == '#' && (retind == 0 || ret[retind-1] == 
'\n' || shellblank (ret[retind - 1])))
+ 
  /* Parse a $(...) command substitution.  This is messier than I'd like, and
     reproduces a lot more of the token-reading code than I'd like. */
***************
*** 3365,3369 ****
              tflags &= ~LEX_RESWDOK;
            }
!         else if (shellbreak (ch) == 0)
  {
              tflags &= ~LEX_RESWDOK;
--- 3377,3383 ----
              tflags &= ~LEX_RESWDOK;
            }
!         else if MBTEST((tflags & LEX_CKCOMMENT) && COMMENT_BEGIN(ch))
!           ;   /* don't turn off LEX_RESWDOK if we're starting a comment */
!         else if MBTEST(shellbreak (ch) == 0)
  {
              tflags &= ~LEX_RESWDOK;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]