Conflict between variable substitution and CJK characters in BASH
- by AndreasT
I encountered a problem with variable substitution in the BASH shell.
Say you define a variable a. Then the command
$> echo ${a//[0-4]/}
prints its value with all the numbers ranged between 0 and 4 removed:
$> a="Hello1265-3World"
$> echo ${a//[0-4]/}
Hello65-World
This seems to work just fine, but let's take a look at the next example:
$> b="?1265-3?"
$> echo ${b//[0-4]/}
?1265-3?
Substitution did not take place: I assume that is because b contains CJK characters. This issue extends to all cases in which square brackets are involved. Surprisingly enough, variable substitution without square brackets works fine in both cases:
$> a="Hello1265-3World"
$> echo ${a//2/}
Hello165-3World
$> b="?1265-3?"
$> echo ${b//2/}
?165-3?
Is it a bug or am I missing something?
I use Lubuntu 12.04, terminal is lxterminal and echo $BASH_VERSION returns 4.2.24(1)-release.
EDIT: Andrew Johnson in his comment stated that with gnome-terminal 4.2.37(1)-release the command works fine. I wonder whether it is a problem of lxterminal or of its specific 4.2.24(1)-release version.