Closed riacataquian closed 3 years ago
Hm. I think you're getting slightly confused, because when you use gosh -c "..."
, that's already double-quoting the input program, so your "inner" double quotes actually get out of the quoting, and back inside.
If you apply the same double quoting to bash, it gets the same result:
$ gosh -c "echo "hello\nnewline"; echo 'hello\\nnewline'"
hellonnewline
hello\nnewline
$ bash -c "echo "hello\nnewline"; echo 'hello\\nnewline'"
hellonnewline
hello\nnewline
A saner approach to test the shells is to start them, paste some input, and then exit:
$ bash
$ echo "hello\nnewline"; echo 'hello\\nnewline'
hello\nnewline
hello\\nnewline
$ exit
exit
$ gosh
$ echo "hello\nnewline"; echo 'hello\\nnewline'
hello\nnewline
hello\\nnewline
$ exit
I should clarify - -c
is entirely fine if your inputs are simple. But if you want to include multiple forms of quoting, then nested quoting gets confusing. Best to start a shell and type in its stdin, or perhaps even a heredoc, like:
$ gosh <<EOF
> echo "foo" 'bar'
> EOF
foo bar
Oh right, I missed the quoting. Thanks for the tips! I'll close this ticket then. :)
interp via gosh produces the result:
But basing from https://www.gnu.org/software/bash/manual/html_node/Escape-Character.html#:~:text=A%20non%2Dquoted%20backslash%20'%20%5C,with%20the%20exception%20of%20newline%20:
The expectation is
\n
is to be treated as a new line and\\n
as a literal value: