Tuesday, January 1, 2013

Display Unicode in Bash

Sometimes you want to use certain characters that only exist in unicode, unfortunately bash doesnt make it super easy to actually output it.

Here are the steps to manually include unicode in ascii bash scripts.

  1. Go find the actual unicode character online that you want to use.
  2. run this: echo -ne 'paste_unicode_here' | hexdump
  3. The result is the hex output of the unicode 
  4. Take the output, place \x before the bytes and use it in your script.

So, for example, if i wanted to use the "┡" character in something, this is what i'd run:
$echo -ne '┡' | hexdump
0000000 e2 94 a1                                       
$echo -ne '\xe2\x94\xa1'

No comments:

Post a Comment