about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-10-25T11·01+0200
committerEelco Dolstra <edolstra@gmail.com>2017-10-25T11·01+0200
commit2d5b1b24bf70a498e4c0b378704cfdb6471cc699 (patch)
tree80e7c28cb3431ed6a3fbb080f769f9016ea564c5 /src/libutil/util.cc
parentac12517f3e969db9fb4834fdfd2da63101ffd3de (diff)
Pass lists/attrsets to bash as (associative) arrays
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 3c98a61f9e50..9346d5dc4cf8 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1142,6 +1142,16 @@ std::string toLower(const std::string & s)
 }
 
 
+std::string shellEscape(const std::string & s)
+{
+    std::string r = "'";
+    for (auto & i : s)
+        if (i == '\'') r += "'\\''"; else r += i;
+    r += '\'';
+    return r;
+}
+
+
 void ignoreException()
 {
     try {