Skip to content

Instantly share code, notes, and snippets.

@colorwebdesigner
Created January 26, 2021 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colorwebdesigner/ef2368b58411defc465772af25e56085 to your computer and use it in GitHub Desktop.
Save colorwebdesigner/ef2368b58411defc465772af25e56085 to your computer and use it in GitHub Desktop.
Bash transliteration script
#!/bin/bash
# translit function
# ----------------------
translit() {
local trs="${1// /-}"
trs=$(sed "y/абвгдезийклмнопрстуфхцы/abvgdezijklmnoprstufxcy/" <<< "${trs}")
trs=$(sed "y/АБВГДЕЗИЙКЛМНОПРСТУФХЦЫ/ABVGDEZIJKLMNOPRSTUFXCY/" <<< "$trs")
trs=${trs//ч/ch}
trs=${trs//Ч/CH}
trs=${trs//ш/sh}
trs=${trs//Ш/SH}
trs=${trs//ё/hyo}
trs=${trs//Ё/HYO}
trs=${trs//ж/zh}
trs=${trs//Ж/ZH}
trs=${trs//щ/sh}
trs=${trs//Щ/SH}
trs=${trs//э/e}
trs=${trs//Э/E}
trs=${trs//ю/ju}
trs=${trs//Ю/JU}
trs=${trs//я/ja}
trs=${trs//Я/JA}
trs=${trs//ъ/}
trs=${trs//Ъ/}
trs=${trs//ь/}
trs=${trs//Ь/}
hash iconv &> /dev/null && trs=$(iconv -c -f UTF8 -t ASCII//TRANSLIT <<< "$trs")
echo "$trs";
}
translit "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment