bug-bash
[Top][All Lists]
Advanced

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

DEL character treated specially when preceded by a backslash when used i


From: Eduardo A . Bustamante López
Subject: DEL character treated specially when preceded by a backslash when used in the RHS of the regex operator ([[ $'\177' =~ $'\\\177' ]])
Date: Thu, 16 Jan 2014 15:46:38 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

The DEL ($'\177') character does not behave like the other control
characters when used with the regex operator inside the test keyword.

This example shows the difference in operation:

address@hidden:~$  for c in $'\001' $'\a' $'\177' $'\377'; do for r in "$c" 
"\\$c" "\\[$c]"; do [[ $c =~ $r ]]; printf '[[ %q =~ %q ]] -> %d\n' "$c" "$r" 
"$?"; done; printf %s\\n ---; done;
[[ $'\001' =~ $'\001' ]] -> 0
[[ $'\001' =~ $'\\\001' ]] -> 0
[[ $'\001' =~ $'\\[\001]' ]] -> 1
---
[[ $'\a' =~ $'\a' ]] -> 0
[[ $'\a' =~ $'\\\a' ]] -> 0
[[ $'\a' =~ $'\\[\a]' ]] -> 1
---
[[ $'\177' =~ $'\177' ]] -> 0
[[ $'\177' =~ $'\\\177' ]] -> 1
[[ $'\177' =~ $'\\[\177]' ]] -> 1
---
[[ $'\377' =~ $'\377' ]] -> 0
[[ $'\377' =~ $'\\\377' ]] -> 0
[[ $'\377' =~ $'\\[\377]' ]] -> 1
---

Notice that only $'\177' seems to fail in the middle case, while the
others work just fine.

I also noticed the following strange behavior in bash under Cygwin:

$ for c in $'\001' $'\a' $'\177' $'\377'; do for r in "$c" "\\$c" "\\[$c]"; do 
[[ $c =~ $r ]]; printf '[[ %q =~ %q ]] -> %d\n' "$c" "$r" "$?"; done; printf 
%s\\n ---; done;
[[ $'\001' =~ $'\001' ]] -> 0
[[ $'\001' =~ $'\\\001' ]] -> 0
[[ $'\001' =~ $'\\[\001]' ]] -> 1
---
[[ $'\a' =~ $'\a' ]] -> 0
[[ $'\a' =~ $'\\\a' ]] -> 0
[[ $'\a' =~ $'\\[\a]' ]] -> 1
---
[[ $'\177' =~ $'\177' ]] -> 0
[[ $'\177' =~ $'\\\177' ]] -> 1
[[ $'\177' =~ $'\\[\177]' ]] -> 1
---
[[ $'\377' =~ $'\377' ]] -> 2
[[ $'\377' =~ $'\\\377' ]] -> 2
[[ $'\377' =~ $'\\[\377]' ]] -> 2
---

Notice the weird return code for non-ASCII characters.

I wonder if this has to do more with the regex library it was
compiled against.

The bash versions:
- cygwin: $ bash --version
GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)
- ubuntu: $ bash --version
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)

(seems to be present in 4.3.x, the DEL character issue)

Why is DEL treated specially when preceded by a backslash in the
regex operator?

-- 
Eduardo Alan Bustamante López



reply via email to

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