@cryptotaxi247 / kubo / commits / 1bd182055

ipfs-test-lib: add shellquote()

This function can be usefull in many places. See for example: https://github.com/ipfs/go-ipfs/pull/1742 Git has `git rev-parse --sq-quote` that does the same thing. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Sep 27, 2015 at 09:08 UTC 1bd182055b5f7d499223284cc36723abc1d836e7
1 file changed +12
test/ipfs-test-lib.sh
+12
@@ -22,3 +22,15 @@ test_sort_cmp() {
22 sort "$2" >"$2_sorted" &&
23 test_cmp "$1_sorted" "$2_sorted"
24 }
25 +
26 +# Quote arguments for sh eval
27 +shellquote() {
28 + _space=''
29 + for _arg
30 + do
31 + printf '%s' "$_space"
32 + printf '%s' "$_arg" | sed -e "s/'/'\\\\''/g; s/^/'/; s/\$/'/;"
33 + _space=' '
34 + done
35 + printf '\n'
36 +}