-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using esceval for shell-escaped command strings
errors have been discussed in more detail in #37 and should be fixed for most use cases with this patch.
- Loading branch information
1 parent
12e8ae4
commit 5e5afea
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# SPDX-License-Identifier: 0BSD | ||
# Copyright 2014 Alexander Kozhevnikov <mentalisttraceur@gmail.com> | ||
|
||
# On 2019-04-25, this script was compatible with Bourne and POSIX shells. | ||
# EXCEPT for the following exceptions: | ||
# Function declarations (First appeared in SVR2 Bourne shells in 1984). | ||
# command built-in (not supported in really old Bourne shells) | ||
|
||
if command -v esceval 1>/dev/null 2>&1 | ||
then | ||
: | ||
else | ||
if (eval 'echo ${A%%a} ${A#a}' 1>/dev/null 2>&1) | ||
then | ||
eval 'esceval() | ||
{ | ||
case $# in 0) return 0; esac | ||
( | ||
while : | ||
do | ||
escaped=\'\'' | ||
unescaped=$1 | ||
while : | ||
do | ||
case $unescaped in | ||
*\'\''*) | ||
escaped=$escaped${unescaped%%\'\''*}"'"'\''"'" | ||
unescaped=${unescaped#*\'\''} | ||
;; | ||
*) | ||
break | ||
esac | ||
done | ||
escaped=$escaped$unescaped\'\'' | ||
shift | ||
case $# in 0) break; esac | ||
printf "%s " "$escaped" || return $? | ||
done | ||
printf "%s\n" "$escaped" | ||
) | ||
}' | ||
else | ||
esceval() | ||
{ | ||
case $# in 0) return 0; esac | ||
( | ||
b='\\' | ||
while : | ||
do | ||
escaped=` | ||
printf '%s\n' "$1" \ | ||
| sed " | ||
s/'/'$b''/g | ||
1 s/^/'/ | ||
$ s/$/'/ | ||
" | ||
` || return $? | ||
shift | ||
case $# in 0) break; esac | ||
printf '%s ' "$escaped" || return $? | ||
done | ||
printf '%s\n' "$escaped" | ||
) | ||
} | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters