-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-if-unicode
69 lines (53 loc) · 2.03 KB
/
check-if-unicode
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# License: GNU GPL v.3 http://www.gnu.org/licenses/gpl-3.0.en.html
# Destiny: Displays if name and text contain unicode characters.
# You can use with file or with pipe "|"
VERSION="beta 1"
# Info: Requires testing.
# Date: 04.2023
# Source: https://github.com/tele1/LinuxScripts
# Script usage: bash script_name file
# or: cat file | bash script_name
#
#===============================================================================
NC='\e[0m' # Reset Color
GN='\e[0;32m' # Green ECHO
RD='\e[0;31m' # Red ECHO
Func_GREEN_ECHO() { echo -e "${GN}$@${NC}" ;}
Func_RED_ECHO() { echo -e "${RD}${@}${NC}" ;}
Func_noascii_quiet() { LANG=C grep -q --color=always '[^ -~]\+' ;}
Func_noascii_show() { LANG=C grep --color=always '[^ -~]\+' ;}
echo " "
if [ -n "$1" ]; then
Var1="$1"
if Func_noascii_quiet <<< "$Var1" ; then
Func_RED_ECHO " This name of file contains Unicode:"
Func_noascii_show <<< "$Var1"
echo " "
Func_RED_ECHO " This is this line with cat -vet:"
cat -vet <<< "$Var1" | grep --color=always 'M-\|\^'
else
Func_GREEN_ECHO " This name of file safe: ascii name"
if Func_noascii_quiet < "$Var1" ; then
Func_RED_ECHO " This file contains Unicode:"
Func_noascii_show < "$Var1"
echo " "
Func_RED_ECHO " This is this line with cat -vet:"
cat -vet < "$Var1" | grep --color=always 'M-\|\^'
else
Func_GREEN_ECHO " This is safe: ascii file"
fi
fi
elif [ -p /dev/stdin ]; then
Var1="$(</dev/stdin)"
if Func_noascii_quiet <<< "$Var1" ; then
Func_RED_ECHO " This file contains Unicode:"
Func_noascii_show <<< "$Var1"
echo " "
Func_RED_ECHO " This is this line with cat -vet:"
cat -vet <<< "$Var1" | grep --color=always 'M-\|\^'
else
Func_GREEN_ECHO "This is safe: ascii file"
fi
fi
echo " "