With Bash, you can use printf
with hex codes
\xHH byte with hexadecimal value HH (1 to 2 digits)
\uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
example
$ printf '\x26'
&
However the Unicode example does not print as expected
$ printf '\u0026'
\u0026
My Bash version
$ echo $BASH_VERSION
4.1.10(4)-release
Use the "\u" escape sequence to print Unicode characters In a string, place "\u" before four hexadecimal digits that represent a Unicode code point.
To include Unicode characters in your Python source code, you can use Unicode escape characters in the form \u0123 in your string. In Python 2. x, you also need to prefix the string literal with 'u'.
Python's string type uses the Unicode Standard for representing characters, which lets Python programs work with all these different possible characters. Unicode (https://www.unicode.org/) is a specification that aims to list every character used by human languages and give each character its own unique code.
Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.
What version of bash
are you using (echo $BASH_VERSION
or bash --version
)? The Unicode escapes work in bash
4.2, but not 3.2.48. I suspect support was added in bash
4.0.
Update: I can confirm it does not work in bash
4.1.2. This functionality appears to have been added in bash
4.2.
Update 2: From the release notes for bash 4.2:
d.
$'...'
,echo
, andprintf
understand\uXXXX
and\UXXXXXXXX
escape sequences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With