From 1bd182055b5f7d499223284cc36723abc1d836e7 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 27 Sep 2015 09:08:29 +0200 Subject: [PATCH] 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 --- test/ipfs-test-lib.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/ipfs-test-lib.sh b/test/ipfs-test-lib.sh index 26821c14a..938e02115 100644 --- a/test/ipfs-test-lib.sh +++ b/test/ipfs-test-lib.sh @@ -22,3 +22,15 @@ test_sort_cmp() { sort "$2" >"$2_sorted" && test_cmp "$1_sorted" "$2_sorted" } + +# Quote arguments for sh eval +shellquote() { + _space='' + for _arg + do + printf '%s' "$_space" + printf '%s' "$_arg" | sed -e "s/'/'\\\\''/g; s/^/'/; s/\$/'/;" + _space=' ' + done + printf '\n' +}