On Fri, Sep 29, 2000 at 01:31:24PM +0200, Ole Kofoed Hansen wrote:
On Thu, 28 Sep 2000, John Grant wrote:
I use perl a lot so I'm particularly susceptable to the version of this problem where I get a command like:
perl -e '$bar = "xyzzy"; print "foo\n\t$bar\n"'
Have you tried this:
perl -e "\$bar = \"xyzzy\"; print \"foo\\n\\t\$bar\\n\""
Which is just with the entire string in double quotes and with all special characters inside escaped with \.
So basically you have to allow for one level of escapes per nesting of quotes, and stay away from single quotes until the outer levels? Also I'd guess that for each level of double quotes you have to add another layer of "\"s to escape the special characters. Taking this to ridiculous extremes, one could do things like: alias xyzzy='echo "`perl -e \"print \\\"foo\\\\n\\\\tbar\\\\n\\\"\"`"' or even bash -c "bash -c \"bash -c \\\"echo -e \\\\\\\"foo\\\\\\\tbar\\\\\\\"\\\"\"" Whew! This could really give that "\" key a workout, since at each new level you have to escape the escapes. I think this is the thing I didn't really understand. ok, I think I'm beginning to get the hang of this now. :) [...]
mini-howto on quoting/escaping in bash?
man bash has a good description. Especially, it mentions that
I looked at the man page but I don't do well with page after page of text. Give me an example (as you did) or two and I'll get much more out of it.
if you enclose a string in 's you cannot use the ' character inside the string - not even if you escape it with a \.
Yes, that is one of the keys. I did realise this, but my problem was understanding how/what to escape and when so I could turn the 's into "s to allow for the "next level" of quoting. Thanks again for the example. It really helped. -John -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/support/faq