echo isn't a great example at all. echo is both OS and SHELL specific.
Not only that, echo has argv to work with; each with it's own terminating
'\0'.
It absolutely can be quite literal, though that doesn't stop the
implementors from doing whatever they want.
Here's a snippet from my own OS's `man echo`:
"Most shells provide a builtin echo command which tends to differ from
this utility in the treatment of options and backslashes. Consult the
builtin(1) manual page."
Here's the cruft of it ......
With a single quoted string ..... containing a single quote itself .......
in any given interpreted language ..... with no EOL or EOF in sight ....
How would you let the interpreter know your done?
The answer: You can't without escaping the single quote.
Some more examples I wrote up.
You'll note, they all use single quotes, yet they all interpret as they
absolutely should.
Example Perl 5:
---------------------------------
# perl -e "print '\''" ;
'
# perl -e "print '\\'" ;
\
# perl -e "print '\a'" ;
\a
Example PHP 7.3:
---------------------------------
# php -r "print '\'';"
'
# php -r "print '\\';"
\
# php -r "print '\a';"
\a
Example python3.6 **unique**:
---------------------------------------
# python3.6 -c "print('\'')"
'
# python3.6 -c "print('\\')"
\
# python3.6 -c "print('\a')" | hexdump -oc | head -1
0000000 005007
On Tue, Dec 3, 2019 at 9:04 PM ToddAndMargo via perl6-users <
[email protected]> wrote:
> On 2019-12-03 17:31, Paul Procacci wrote:
> > When a string is specified in single quotes, perl6 (or any other
> > language that I'm aware of) will not evaluate or interpret an escape
> > character EXCEPT when the escape is follow'd by a single quote (') or
> > backslash(\).
> > These HAVE to be escaped and the interpreter HAS to account for it.
>
> Hi Paul,
>
> I am not finding that to be the case. Well maybe not Perl 5.
>
> $ bash -c "echo '\'"
> \
>
> $ echo '\\\'
> \\\
>
> $ echo '\\'
> \\
>
> $ echo '\'
> \
>
>
> If it is on purpose and not a "feature" in Perl 6, then
> the documentation should state that single quotes will
> have interpretations inside of them in certain cases.
>
>
> Ahh Perl 5 is a pain in the butt backslash wise!
>
> $ perl -e "CORE::say '\\\\';"
> \
>
> And I am seeing in
> https://docs.perl6.org/language/quoting
> Literal strings: Q
> Q[A literal string]
>
> Is the way I have been using single quotes.
>
> So the rule is single quotes are literal, unless a backslash
> in included, then use Q
>
> Thank you for the help!
>
> -T
>
--
__________________
:(){ :|:& };: