On 2019-12-03 19:14, Paul Procacci wrote:
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
You make a good point.
Bash language may be the exception then:
$ cat echo.sh
#!/usr/bin/bash
echo '\'
linuxutil]$ echo.sh
\
"echo" does not recognize interpretation unless you invoke
it with -e
$ echo -e '\\'
\