aboutsummaryrefslogtreecommitdiffstats
path: root/awklib/eg/lib/shellquote.awk
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-10-01 21:41:24 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-10-01 21:41:24 +0300
commit63cf4c66e97a92f3e553707ecd0bc278a7cc4563 (patch)
treea885bea63fd2e8636d2dd7d7e7a1b3ea646b0c8f /awklib/eg/lib/shellquote.awk
parent63c4c29e1ebfb0e68fe622bea1c4ed82ac6a6a02 (diff)
downloadegawk-63cf4c66e97a92f3e553707ecd0bc278a7cc4563.tar.gz
egawk-63cf4c66e97a92f3e553707ecd0bc278a7cc4563.tar.bz2
egawk-63cf4c66e97a92f3e553707ecd0bc278a7cc4563.zip
More doc updates.
Diffstat (limited to 'awklib/eg/lib/shellquote.awk')
-rw-r--r--awklib/eg/lib/shellquote.awk22
1 files changed, 22 insertions, 0 deletions
diff --git a/awklib/eg/lib/shellquote.awk b/awklib/eg/lib/shellquote.awk
new file mode 100644
index 00000000..cd943dc7
--- /dev/null
+++ b/awklib/eg/lib/shellquote.awk
@@ -0,0 +1,22 @@
+# shell_quote --- quote an argument for passing to the shell
+#
+# Michael Brennan
+# brennan@madronabluff.com
+# September 2014
+
+function shell_quote(s, # parameter
+ SINGLE, QSINGLE, i, X, n, ret) # locals
+{
+ if (s == "")
+ return "\"\""
+
+ SINGLE = "\x27" # single quote
+ QSINGLE = "\"\x27\""
+ n = split(s, X, SINGLE)
+
+ ret = SINGLE X[1] SINGLE
+ for (i = 2; i <= n; i++)
+ ret = ret QSINGLE SINGLE X[i] SINGLE
+
+ return ret
+}