-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenco
executable file
·43 lines (39 loc) · 865 Bytes
/
enco
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
_where_am_i="$(dirname "$([[ -h "$0" ]]&&readlink $0||which $0)" 2> /dev/null)"
if [[ -z "${_where_am_i}" ]]; then
_where_am_i="$(dirname $0)"
fi
# to combine to one script, replace code below with enco.src code
_src_file="${_where_am_i}/enco.src"
if [[ -f "${_src_file}" ]]; then
source "${_src_file}"
else
echo " Source file \"${_src_file}\" dose not exist."
exit 1
fi
# to combine to one script, replace code above with enco.src code
#main begin
echo
if [[ ( $1 == "-t" || $1 == "--to-charset" ) && $2 && $3 ]]; then
:
else
_usage_f
fi
case "$(echo $2|tr "[A-Z]" "[a-z]")" in
"utf8"|"utf-8")
DST_CHARSET="utf8"
SRC_CHARSET="gb18030"
;;
"gb18030"|"gbk")
DST_CHARSET="gb18030"
SRC_CHARSET="utf8"
;;
*)
echo "${MARGIN} Unsupported charset \"$2\", supported charset: UTF-8, GB18030."
echo
exit 1
;;
esac
shift 2
_convert $@
echo