On 5/3/12 5:53 AM, Ruediger Kuhlmann wrote:
> Hi,
> 
> please try the following bash script:
> 
> a=x
> del="$(echo -e "\\x7f")"
> 
> echo "$del${a#x}" | od -ta
> echo "$del ${a#x}" | od -ta
> echo " $del${a#x}" | od -ta
> 
> Using bash 3.2, the output is:
> 
> 0000000 del  nl
> 0000002
> 0000000 del  sp  nl
> 0000003
> 0000000  sp del  nl
> 0000003
> 
> however with bash 4.1 and bash 4.2.20, the output is only:
> 
> 0000000 del  nl
> 0000002
> 0000000  sp  nl
> 0000002
> 0000000  sp  nl
> 0000002
> 
> ... so in the second and third line, the delete character magically
> disappears. Neither OS nor locale seem to influence this. Using a delete
> character directly in the script instead of $del also has no impact, either.
It's a case of one part of the code violating assumptions made by (and
conditions imposed by) another.  Try the attached patch; it fixes the
issue for me.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/
*** ../bash-20120427/subst.c	2012-04-22 16:19:10.000000000 -0400
--- subst.c	2012-05-07 16:06:35.000000000 -0400
***************
*** 8160,8163 ****
--- 8160,8171 ----
  	  dispose_word_desc (tword);
  
+ 	  /* Kill quoted nulls; we will add them back at the end of
+ 	     expand_word_internal if nothing else in the string */
+ 	  if (had_quoted_null && temp && QUOTED_NULL (temp))
+ 	    {
+ 	      FREE (temp);
+ 	      temp = (char *)NULL;
+ 	    }
+ 
  	  goto add_string;
  	  break;
***************
*** 8568,8572 ****
        if (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES))
  	tword->flags |= W_QUOTED;
!       if (had_quoted_null)
  	tword->flags |= W_HASQUOTEDNULL;
        list = make_word_list (tword, (WORD_LIST *)NULL);
--- 8576,8580 ----
        if (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES))
  	tword->flags |= W_QUOTED;
!       if (had_quoted_null && QUOTED_NULL (istring))
  	tword->flags |= W_HASQUOTEDNULL;
        list = make_word_list (tword, (WORD_LIST *)NULL);
***************
*** 8599,8603 ****
  	  if (word->flags & W_NOEXPAND)
  	    tword->flags |= W_NOEXPAND;
! 	  if (had_quoted_null)
  	    tword->flags |= W_HASQUOTEDNULL;	/* XXX */
  	  list = make_word_list (tword, (WORD_LIST *)NULL);
--- 8607,8611 ----
  	  if (word->flags & W_NOEXPAND)
  	    tword->flags |= W_NOEXPAND;
! 	  if (had_quoted_null && QUOTED_NULL (istring))
  	    tword->flags |= W_HASQUOTEDNULL;	/* XXX */
  	  list = make_word_list (tword, (WORD_LIST *)NULL);

Reply via email to