I’m not really stuck on Stage #QJ0 but wanted to report what I think is a wrong test case.
It’s particularly about the executable `exe with \‘single quotes\’`. The test case tries to call that executable via the command
[your-program] $ "exe with \'single quotes\'" /tmp/ant/f3
Please note the single backslashes (`\`) before the single quotes. If a quoted executable name must be interpreted like a quoted argument, as the text in #QJ0 states, those single backslashes would escape the single quotes.
I’ve listed the directory on the test runner which contains the executables. The particular executable’s file name also contains backslashes:
[your-program] "Listing /tmp/pig"
[your-program] cat
[your-program] exe with space
[your-program] exe with "quotes"
[your-program] exe with \'single quotes\'
[your-program] exe with \n newline
[your-program] f1
[your-program] f2
[your-program] f3
[your-program] f4
[your-program] strawberry blueberry.
[your-program] $
So, the correct command line to issue in the test must be
[your-program] $ "exe with \\'single quotes\\'" /tmp/ant/f3
Please note the escaped backslashes.
I’m not really stuck because I can work around this issue.
To be clear with the input given: "exe with \'single quotes\'" parsing it should give exe with \'single quotes\'.
I think you might misunderstand the escaping rules. Inside " here " the character \ only escapes some symbols, and ' is not one of them. So "\'" is \' and not ', the backslash is a literal part of the result.
To expand, the previous stage gu3 covers this and says:
Within double quotes, a backslash only escapes certain special characters: ", \, $, `, and newline
If you look at Bash manual it says the same thing
Enclosing characters in double quotes (") preserves the literal value of all characters within the quotes, with the exception of $, `, \, … The characters $ and ` retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified.
But yeah it is counterintuitive, because in most languages and context \ is an universal escaper that works for any following character.
Hey @oliver-brm, as @senevoldsen mentioned, the backslash is treated as a literal character here, so \' should be parsed as a backslash followed by a single quote, not as an escaped quote.
That said, you’re absolutely right that the current test case is confusing and easy to misinterpret. We’re updating it to make the expected behavior clearer in this PR.