Hex escape sequences in bash regex range have no effect
From what I can tell, Bash doesn’t support this syntax.* Instead, you can use C-style quoting:
[[ "$char" =~ ^[$'\x01'-$'\x20'$'\x7F'-$'\xFF']$ ]]
* My research: Bash documentation for [[:
An additional binary operator, ‘
=~‘, is available, with the same precedence as ‘==‘ and ‘!=‘. When you use ‘=~‘, the string to the right of the operator is considered a POSIX extended regular expression pattern and matched accordingly (using the POSIXregcompandregexecinterfaces usually described in regex(3)).
regex(3) on my machine points to regex(7), which says:
a ‘
\‘ followed by any other character(!) (matching that character taken as an ordinary character, as if the ‘\‘ had not been present(!))
POSIX.2 leaves some aspects of RE syntax and semantics open; “(!)” marks decisions on these aspects that may not be fully portable to other POSIX.2 implementations.
Read more here: Source link
