forked from legionus/libshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell-string
39 lines (36 loc) · 834 Bytes
/
shell-string
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
#!/bin/sh -efu
### This file is covered by the GNU General Public License,
### which should be included with libshell as the file LICENSE.
### All copyright information are listed in the COPYING.
if [ -z "${__included_shell_string-}" ]; then
__included_shell_string=1
### Creates a mask of equal length string.
### Usage: fill_mask var str [full-length]
fill_mask()
{
__fill_mask()
{
local m=
while :; do
case $((${#1} - ${#m})) in
0) break ;;
1) m="$m?" ;;
2) m="$m??" ;;
3) m="$m???" ;;
4) m="$m????" ;;
5) m="$m?????" ;;
6) m="$m??????" ;;
7) m="$m???????" ;;
8) m="$m????????" ;;
9) m="$m?????????" ;;
*) m="$m??????????" ;;
esac
done
__fill_masko="${m#$2}"
}
local __fill_masko
__fill_mask "$2" "${3:-?}"
unset -f __fill_mask
eval "$1=\$__fill_masko"
}
fi #__included_shell_string