Closed ezrizhu closed 2 months ago
The solution is to appropriately quote when we generate $script_to_execute
. A basic version of this would not be too hard, but subtleties of escaping abound.
Would be easily resolved in a rewrite not in the shell.
for arg in "$@"
do
case $arg in
(*[$(printf " \n\t()<>&;|\`?*\$\"'")\\]*)
quoted=$(echo "$arg" | sed -e "s/'/'\\\\''/")
printf "'%s' " "$quoted";;
(*) printf "%s " "$arg";;
esac
done
printf "\n"
is a workable first cut.
Our tests expect that try "echo hi>foo"
will preserve the redirect and that try "echo hi; echo bye"
will preserve the pair of commands.
I don't see how we can support both this existing behavior and appropriate quoting of things like bash -c
. An advantage of the current behavior is that you can run try "bash -c \"echo hi\""
and get the right behavior... whereas it's not clear how to preserve the shell syntax with this modified behavior.
Unless you have a better idea, I'll delete the branch and close the issue.
I don't have a better idea, feel free to delete the branch. I'll close the issue once the docs has been updated.
try bash -c "echo a"
actually executesbash -c echo a