Escaped quotation mark not handled properly
d4h0 opened this issue · comments
The following:
let foobar = "foo bar";
xshell::cmd!("ls \"{foobar}\"");
fails with:
error[E0765]: unterminated double quote string
--> websites/print_css/src/main.rs:90:29
|
90 | ... xshell::cmd!("ls \"{foobar}\"");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adding a space after the last escaped quotation mark works:
let foobar = "foo bar";
xshell::cmd!("ls \"{foobar}\" ");
I also just found out, that escaped quotation marks are not handled properly, when a command is executed.
I believe these both issues are related to each other, so I'll not create a new issue for this (but let me know if that would make more sense).
The following:
xshell::cmd!("echo \"foo\" ").run()?
prints:
$ echo "foo"
"foo"
But echo "foo"
prints foo
without quotation marks.
So it seems, xshell
really is executing echo "\"foo\""
above.
As far as I can see, currently it's not possible to execute a command like ls "foo bar"
, where foo bar
is a directory with a space in it. At least, if part of foo bar
comes from a variable (otherwise ls 'foo bar'
could be used, I believe. However, variables are not interpolated within single quotation marks).
The following is probably a better demonstration:
let foo = "foo bar"
xshell::cmd!("echo \"foo bar/{foo}\" ").run()?
which prints:
$ echo "foo "bar/foo bar\""
"foo bar/foo bar"