Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Fwd: Bash bug interpolating delete characters

2 views
Skip to first unread message

Greg Wooledge

unread,
May 3, 2012, 9:01:04 AM5/3/12
to Chet Ramey, Bug-...@gnu.org
> Yours, Rüdiger.

> a=x
> del="$(echo -e "\\x7f")"
>
> echo "$del${a#x}" | od -ta
> echo "$del ${a#x}" | od -ta
> echo " $del${a#x}" | od -ta

Yup, confirmed that it breaks here, and only when the # parameter expansion
is included.

imadev:~$ del=$'\x7f' a=x b=
imadev:~$ echo " $del$b" | od -ta
0000000 sp del nl
0000003
imadev:~$ echo " $del${b}" | od -ta
0000000 sp del nl
0000003
imadev:~$ echo " $del${b#x}" | od -ta
0000000 sp del nl
0000003
imadev:~$ echo " $del${a#x}" | od -ta
0000000 sp nl
0000002

Bash 4.2.24.

John Kearney

unread,
May 3, 2012, 1:41:31 PM5/3/12
to bug-...@gnu.org
Also Confirmed, but my output is a bit wackier.
printf %q seems to get confused, and do invalid things as well.

the \x7f becomes a \

function printTests {
while [ $# -gt 0 ]; do
printf "%-20s=[%q]\n" "${1}" "$(eval echo "${1}")"
shift
done
}

a=x
del=$'\x7f'
printTests '"$del${a#x}"' '"$del ${a#x}"' '" $del${a#x}"' '" $del${a%x}"'
printTests '" $del${a:0:0}"' '" $del"${a:0:0}' '" $del""${a:0:0}"'
printTests '" $del${a}"' '" $del"' '" ${del}${a:0:0}"' '"
${del:0:1}${a:0:0}"'
printTests '" ${del:0:1}${a}"' '"${del:0:1}${a#d}"' '"${del:0:1}${a#x}"'
printTests '" ${del:0:1} ${a}"' '"${del:0:1} ${a#d}"' '"${del:0:1} ${a#x}"'

output
"$del${a#x}" =[$'\177']
"$del ${a#x}" =[\ ]
" $del${a#x}" =[\ ]
" $del${a%x}" =[\ ]
" $del${a:0:0}" =[\ ]
" $del"${a:0:0} =[$' \177']
" $del""${a:0:0}" =[$' \177']
" $del${a}" =[$' \177x']
" $del" =[$' \177']
" ${del}${a:0:0}" =[\ ]
" ${del:0:1}${a:0:0}"=[\ ]
" ${del:0:1}${a}" =[$' \177x']
"${del:0:1}${a#d}" =[$'\177x']
"${del:0:1}${a#x}" =[$'\177']
" ${del:0:1} ${a}" =[$' \177 x']
"${del:0:1} ${a#d}" =[$'\177 x']
"${del:0:1} ${a#x}" =[\ ]






John Kearney

unread,
May 3, 2012, 1:44:02 PM5/3/12
to bug-...@gnu.org
disregard the comment about printf its just escaping the space.

John Kearney

unread,
May 7, 2012, 8:01:05 PM5/7/12
to bug-...@gnu.org
Am 07.05.2012 22:46, schrieb Chet Ramey:
> 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
>
It also works for me.

"$del${a#x}" =[$'\177']
" $del${a%x}" =[$' \177']
" $del""${a:0:0}" =[$' \177']
" ${del}${a:0:0}" =[$' \177']
"${del:0:1}${a#d}" =[$'\177x']
"${del:0:1} ${a#d}" =[$'\177 x']
"${del:0:1} ${a:+}" =[$'\177 ']
"$del ${a#x}" =[$'\177 ']
" $del${a:0:0}" =[$' \177']
" $del${a}" =[$' \177x']
" ${del:0:1}${a:0:0}" =[$' \177']
"${del:0:1}${a#x}" =[$'\177']
"${del:0:1} ${a#x}" =[$'\177 ']
" $del${a#x}" =[$' \177']
" $del"${a:0:0} =[$' \177']
" $del" =[$' \177']
" ${del:0:1}${a}" =[$' \177x']
"${del:0:1} ${a}" =[$'\177 x']
"${del:0:1} ${a:-}" =[$'\177 x']


0 new messages