-
-
Save fami-com/d02e5cde7df177a5dffc584c5b6d7dfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# enkoi - encode a text from cp1251 to koi8-r | |
# options: -e switch to encode mode | |
# -d switch to decode mode | |
# licensed under the terms of MIT license | |
# | |
version="0.1" | |
function helpexit () | |
{ | |
printf "Usage: %s [-e|-d] [OPTION]...\n" $(basename $0) | |
exit 1 | |
} >&2 | |
if [ "$#" -lt 1 ] | |
then | |
helpexit | |
fi | |
tmp="$1" | |
if [[ $1 = '-e' ]] || [[ $1 = '-d' ]] | |
then | |
shift | |
fi | |
for i in "$@" | |
do | |
case "$tmp" in | |
"-d" ) | |
echo $i | tr '\n' ' ' | iconv -t koi8-r | iconv -f cp1251 | |
;; | |
"-e" ) | |
echo $i | tr '\n' ' ' | iconv -t cp1251 | iconv -f koi8-r | |
;; | |
* ) | |
helpexit | |
;; | |
esac | |
done | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment