forked from Wizcorp/libbash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.sh
72 lines (57 loc) · 1.24 KB
/
query.sh
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
68
69
70
71
72
#!/bin/bash
query(){
local resultvar=${1:-};
local ret;
shift;
if [ "${1:-}" == "" ]; then
while read data; do
echo -n $data
done
else
while test $# -gt 0; do
if [ "${1:-}" != "" ]; then
echo -n " ${1:-}";
shift
fi
done
fi
echo -n ": "
read ret;
eval $resultvar="'$ret'"
}
queryStared(){
local resultvar=${1:-};
local ret;
shift;
if [ "${1:-}" == "" ]; then
while read data; do
echo -n $data
done
else
while test $# -gt 0; do
echo -n " ${1:-}";
shift
done
fi
echo -n ": "
prompt="";
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]; then
break
elif [ "$(echo -ne $char | cat -A -)" == "^?" ]; then
prompt="";
if [ "$(echo $ret | wc -c)" != "1" ]; then
echo -ne "\b\c";
echo -ne " ";
echo -ne "\b\c";
ret=$(echo $ret | sed "s/.$//")
fi
continue;
fi
prompt='*'
ret+="$char"
done
echo "";
eval $resultvar="'$ret'"
}