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 <chriscool@tuxfamily.org>
Christian Couder committed
Oct 3, 2015 at 23:35 UTC
088aa1a62347cb550bd8df6e8cb5129543b43839
1 file changed
+3
-2
test/ipfs-test-lib.sh
+3
-2
@@ -28,8 +28,9 @@ shellquote() {
28
_space=''
29
for _arg
30
do
31
- printf '%s' "$_space"
32
- printf '%s' "$(printf '%s' "$_arg" | sed -e "s/'/'\\\\''/g; s/^/'/; s/\$/'/;")"
31
+ # On Mac OS, sed adds a newline character.
32
+ # With a printf wrapper the extra newline is removed.
33
+ printf "$_space'%s'" "$(printf "%s" "$_arg" | sed -e "s/'/'\\\\''/g;")"
34
_space=' '
35
done
36
printf '\n'