Reputation: 3266
I'm not a newbie to shell, but still got confused with some not so complex quotation problems. I guess there must be something misunderstood.
a: echo 'Don\'t quote me // Don quote me
b: echo Don'\t' quote me // Don quote me
c: echo Don\t quote me // Dont quote me
d: echo Don"\t" qoute me // Don quote me
Above three quotations go quite against my intuition. Doesn't single quote '...'
literally returns what is quoted? What I thought is..
For a: in single quoted 'Don\'
, \
is nothing but a common character. So a) should be Don\t quote me
.
For b: like a), '\t'
suppressed the special meaning of \t
, so I thought b) should be Don\t quote me
too.
For c: I understand why c works, but don't understand the diff between a&b and c.
For d: no difference between '
and "
?
Probably I misunderstand how shell
parse and execute the line of command..
Problem solved by using /bin/echo
instead of (built-in)echo
on Mac. Latter one will interpret backslash.
Upvotes: 3
Views: 477
Reputation: 6749
As per bash
Why:
Upvotes: 3
Reputation: 4335
Your understanding of shell quoting is correct, but it appears that echo
on OSX is a shell builtin which interprets backslash escapes. This behavior can be turned off by executing shopt -u xpg_echo
.
See here for more information: How can I escape shell arguments in AppleScript?
Upvotes: 3