Bash

訪問 UTF-8 楔形文字數字和標點符號

  • August 13, 2021

有人知道如何訪問 UTF-8 楔形文字數字和標點符號嗎?

 twash="\u12400"       # two ash
 thash="\u12401"       # three ash
 frash="\u12402"       # four ash
 fvash="\u12403"       # five ash
 sxash="\u12404"       # six ash
 svash="\u12405"       # seven ash
 eiash="\u12406"       # eight ash
 niash="\u12407"       # nine ash
 thdsh="\u12408"       # three dish
 frdsh="\u12409"       # four dish
 fvdsh="\u1240a"       # five dish
 sxdsh="\u1240b"       # six dish
 svdsh="\u1240c"       # seven dish
 eidsh="\u1240d"       # eight dish
 nidsh="\u1240e"       # nine dish
 fru="\u1240f"         # four u

以下確實讓我得到了正確的數字元號。

 echo ""
 echo "> cunif-numpc-utf-scout"

 echo -e "twash: $twash" "| thash: $thash" "| frash: $frash" "|" \
         "fvash: $fvash"

 echo -e "sxash: $sxash" "| svash: $svash" "| eiash: $eiash" "|" \
         "niash: $niash"

 echo -e "thdsh: $thdsh" "| frdsh: $frdsh" "| fvdsh: $fvdsh" "|" \
         "sxdsh: $sxdsh"

 echo -e "svdsh: $svdsh" "| eidsh: $eidsh" "| nidsh: $nidsh" "|" \
         "fru: $fru"

你必須使用\UHHHHH,而不是\uHHHHH。小寫的u只允許最多四個十六進制數字作為轉義序列的一部分。大寫的U最多允許 8 個。

有了這個改變,你應該得到

> cunif-numpc-utf-scout
twash: 𒐀 | thash: 𒐁 | frash: 𒐂 | fvash: 𒐃
sxash: 𒐄 | svash: 𒐅 | eiash: 𒐆 | niash: 𒐇
thdsh: 𒐈 | frdsh: 𒐉 | fvdsh: 𒐊 | sxdsh: 𒐋
svdsh: 𒐌 | eidsh: 𒐍 | nidsh: 𒐎 | fru: 𒐏

(當然,取決於您的終端呈現這些字元的能力)

您還可以使用所謂的 ANSI-C quoting將變數直接設置為這些字元,而不必依賴echo轉義序列:bash

twash=$'\U12400'

引用自:https://unix.stackexchange.com/questions/664482