-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg4.sh
executable file
·52 lines (42 loc) · 1.06 KB
/
arg4.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
#!/bin/sh
[ -t 1 ] && [ -t 2 ] && {
IFS=''
i=$*
printf '%i:%i ' "$#" "${#i}"
} >&2
case $# in 0) echo; exit; esac
#log() { printf %s\\n " --> $*" >&2; }
log() { :; }
_arg4_tmp_=${BASH_VERSION-${ASH_VERSION-${ZSH_VERSION-${KSH_VERSION-${YASH_VERSION-$( (eval 'a=" "; echo ${a/" "/x}') 2>/dev/null 1>&2 )}}}}}
case $?:$_arg4_tmp_ in # doesnt work for `dash`, `posh`, (older version of working shell are never tested)
0:*[!" "]*)
eval "_escape_() { printf %s\\\\n \"${1//\\'/\\'\\\\\\'\\'}\"; }"
;;
*)
_escape_() {
case $1 in *"'"*) ;; *)
log using replacement
printf %s "'$1'"
return
esac
case ${#1} in [0-9]|[0-9][0-9]) # calling `sed` might be slow for many short strings
_arg4_tmp_=$1
printf "'"
while case $_arg4_tmp_ in *"'"*) ;; *) false; esac; do
printf %s "${_arg4_tmp_%%\'*}'\''";
_arg4_tmp_=${_arg4_tmp_#*"'"}
done
printf %s "$_arg4_tmp_'"
return
esac
log using sed
printf %s "$1" | sed "s/'/'\\\\''/g; 1s/^/'/; $s/$/' /"
}
esac
while :; do
_escape_ "$1"
shift
case $# in 0) break; esac
printf " "
done
echo