diff --git a/test/quoted_arguments.sh b/test/quoted_arguments.sh new file mode 100755 index 00000000..d938d031 --- /dev/null +++ b/test/quoted_arguments.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}" +TRY="$TRY_TOP/try" + +cleanup() { + cd / + + if [ -d "$try_workspace" ] + then + rm -rf "$try_workspace" >/dev/null 2>&1 + fi + + if [ -f "$expected" ] + then + rm "$expected" + fi +} + +trap 'cleanup' EXIT + +try_workspace="$(mktemp -d)" +cd "$try_workspace" || exit 9 + +expected="$(mktemp)" +cat >"$expected" <<'EOF' +hello world +it's ok +EOF + +arg1="hello world" +arg2="it's ok" + +"$TRY" printf '%s\n' "$arg1" "$arg2" >out.txt || exit 1 + +diff -q "$expected" out.txt diff --git a/try b/try index 4aedd742..9ac3500f 100755 --- a/try +++ b/try @@ -293,7 +293,13 @@ cd "$START_DIR" && OLDPWD=$OLDPWD . "$script_to_execute" EOF - echo "$@" >"$script_to_execute" + { + printf '#!/bin/sh\nexec' + for arg in "$@"; do + printf ' %s' "'$(printf %s "$arg" | sed "s/'/'\"'\"'/g")'" + done + printf '\n' + } >"$script_to_execute" # `$script_to_execute` need not be +x to be sourced chmod +x "$mount_and_execute" "$chroot_executable"