How do you echo a 4-digit Unicode character in Bash?

后端 未结 18 2045
醉梦人生
醉梦人生 2020-11-29 14:38

I\'d like to add the Unicode skull and crossbones to my shell prompt (specifically the \'SKULL AND CROSSBONES\' (U+2620)), but I can\'t figure out the magic incantation to m

18条回答
  •  孤城傲影
    2020-11-29 15:02

    In bash to print a Unicode character to output use \x,\u or \U (first for 2 digit hex, second for 4 digit hex, third for any length)

    echo -e '\U1f602'
    

    I you want to assign it to a variable use $'...' syntax

    x=$'\U1f602'
    echo $x
    

提交回复
热议问题