summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorStefan Bodewig <bodewig@apache.org>2016-10-26 15:43:10 +0200
committerStefan Bodewig <bodewig@apache.org>2016-10-26 15:43:10 +0200
commit61e1cccf303dd7b1c42026e9544c3733031a3249 (patch)
tree9aac650ebc844846eddadcb79c3ea76424347522 /src/script
parentc385fc66ff46ad604e59c15212014bf3fa655575 (diff)
downloadant-61e1cccf303dd7b1c42026e9544c3733031a3249.tar.gz
latest iteration of Jeff Adamson's script fixes
known to not completely break in Solaris
Diffstat (limited to 'src/script')
-rw-r--r--src/script/ant27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/script/ant b/src/script/ant
index 8cc8f8e93..0f83e183f 100644
--- a/src/script/ant
+++ b/src/script/ant
@@ -24,6 +24,15 @@ show_help=false
esc_tool=sed
+# if awk esc_tool is chosen, use nawk when available
+if [ "$esc_tool" = "awk" ]
+then
+ awk_exec=awk
+ # Solaris_awk does not support gsub, but Solaris_nawk does
+ # `command -v` behavior is part of posix spec
+ command -v nawk >/dev/null && awk_exec=nawk
+fi
+
for arg in "$@" ; do
if [ "$arg" = "--noconfig" ] ; then
no_config=true
@@ -40,19 +49,21 @@ for arg in "$@" ; do
fi
# wrap all arguments as "" strings, escape any internal back-slash, double-quote, $, or back-tick characters
- # use printf to avoid echo modification behaviors such as escape and line continuation
- # pad the value with leading/trailing X to protect trailing newlines and whitespace from awk and sed
+ # use printf to avoid echo interpretation behaviors such as escapes and line continuation
+ # pad the value with leading/trailing X to protect whitespace
esc_arg="X${arg}X"
case "$esc_tool" in
'sed')
- # mac sed does not support group-0, so pattern uses group-1
- esc_arg="$(printf '%s' "$esc_arg" | sed -e 's@\([$"\\`]\)@\\\1@g')"
+ # Mac bsd_sed does not support group-0, so pattern uses group-1
+ # Solaris sed only proceses lines with trailing newline, passing in an extra newline
+ # sed will consume the trailing newline
+ esc_arg="$(printf '%s\n' "$esc_arg" | sed -e 's@\([$"\\`]\)@\\\1@g')"
;;
'awk')
- esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/\\/, "\\\\"); print }' )"
- esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/\$/, "\\$"); print }' )"
- esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/\"/, "\\\""); print }' )"
- esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/`/, "\\`"); print }' )"
+ esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\\/, "\\\\"); print }' )"
+ esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\$/, "\\$"); print }' )"
+ esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\"/, "\\\""); print }' )"
+ esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/`/, "\\`"); print }' )"
;;
# 'bash')
# # does not depend upon `sed` or `echo` quirks