From 088aa1a62347cb550bd8df6e8cb5129543b43839 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 3 Oct 2015 23:35:26 +0200 Subject: [PATCH] ipfs-test-lib: clarify and simplify shellquote() Let's first add a comment to explain why the wrapper printf() is needed. Then let's replace the last instructions by quotes inside the wrapper printf() first argument, and let's also put there the eventual space so that we can remove the printf on the above line. License: MIT Signed-off-by: Christian Couder --- test/ipfs-test-lib.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/ipfs-test-lib.sh b/test/ipfs-test-lib.sh index 040addd82..b05287c2e 100644 --- a/test/ipfs-test-lib.sh +++ b/test/ipfs-test-lib.sh @@ -28,8 +28,9 @@ shellquote() { _space='' for _arg do - printf '%s' "$_space" - printf '%s' "$(printf '%s' "$_arg" | sed -e "s/'/'\\\\''/g; s/^/'/; s/\$/'/;")" + # On Mac OS, sed adds a newline character. + # With a printf wrapper the extra newline is removed. + printf "$_space'%s'" "$(printf "%s" "$_arg" | sed -e "s/'/'\\\\''/g;")" _space=' ' done printf '\n'