1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 07:28:20 +08:00

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>
This commit is contained in:
Christian Couder
2015-10-03 23:35:26 +02:00
parent 4cab9fe37e
commit 088aa1a623

View File

@ -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'