Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode characters in /bin/sh VS /bin/bash

Please try:

bash -c "printf '\u2744'"
bash -c "echo -e '\u2744'"

And so:

sh -c "printf '\u2744'"
sh -c "echo -e '\u2744'"

Why in /bin/bash I can get that unicode character but not in /bin/sh? How to print a unicode characer (for example ) in /bin/sh?

like image 792
Valerio Bozz Avatar asked Feb 27 '26 04:02

Valerio Bozz


1 Answers

If you want to print a unicode character in /bin/sh (which isn't required by POSIX to support \u sequences), either embed it literally in your script or break it down into its component bytes and print those individually.

For the snowflake symbol used in the question:

printf '\342\235\204'

Now, how do you find those numbers? The easiest way is to use od from a shell that does support unicode:

$ printf '\u2744' | od -b
0000000 342 235 204
like image 137
Charles Duffy Avatar answered Mar 01 '26 18:03

Charles Duffy