On Thu, Mar 28, 2019 at 09:30:43PM +0100, Norman H. Azadian wrote: > Description: > In version 4 [A-Z] is broken and [:upper:] works. > In version 5, the situation is reversed. > > Repeat-By: > foo=ABC ; echo ${foo%[A-Z]} ${foo%[:upper:]}
You have two problems here. Well, four really. First, your first example invokes platform-defined behavior. [A-Z] isn't safe to use unless one of the criteria described below are met: [...] Matches any one of the enclosed characters. A pair of characters separated by a hyphen denotes a range expres‐ sion; any character that falls between those two charac‐ ters, inclusive, using the current locale's collating sequence and character set, is matched. If the first character following the [ is a ! or a ^ then any charac‐ ter not enclosed is matched. The sorting order of char‐ acters in range expressions is determined by the current locale and the values of the LC_COLLATE or LC_ALL shell variables, if set. To obtain the traditional interpreta‐ tion of range expressions, where [a-d] is equivalent to [abcd], set value of the LC_ALL shell variable to C, or enable the globasciiranges shell option. A - may be matched by including it as the first or last character in the set. A ] may be matched by including it as the first character in the set. Second, your second example should be using [[:upper:]] not [:upper:]. You might be mixing up tr's syntax with glob/regex syntax. Also, you didn't tell us what result you got, or what result you expected to see. And you forgot to quote. wooledg:~$ var=ABC; echo "${var%[[:upper:]]}" AB wooledg:~$ LC_COLLATE=C; var=ABC; echo "${var%[A-Z]}" AB wooledg:~$ unset LC_COLLATE; shopt -s globasciiranges; var=ABC; echo "${var%[A-Z]}" AB