unicode.sh 320 B

1234567891011121314151617181920
  1. # shellcheck shell=sh
  2. # unicode to hex
  3. u2x() (
  4. for u; do
  5. # shellcheck disable=2005,2046
  6. printf '%s\n' $(
  7. printf %b "${u}" |
  8. iconv -f UTF-8 -t UTF-16 |
  9. od --endian=big -An -N2 -x
  10. )
  11. done
  12. )
  13. # hex to unicode
  14. x2u() {
  15. # shellcheck disable=2046
  16. [ "${1:-}" ] && printf '%b\n' $(printf '\\u%s\n' "${@}")
  17. }