On Fri, Sep 29, 2000 at 10:33:54AM -0400, D E Hammond wrote:
On 29 Sep, 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\""
< [...]
This doesn't answer the real question about quoting and escaping. Ole has the right answer there by suggesting the bash man page, since it is a shell issue - and sometimes a confusing one at that. But narrowly
Tell me about it. :) Actually not so hard I guess. I just never sat down and figured it out before.
targeting the perl one-liners, you can usually get by without escaping quotes, unless you need a literal one. Multiple pairs of single quotes inside of double quotes are ok, as are multiple pairs of double quotes inside single ones. In those instances where you need nested quotes of the same variety, or just don't to think about it, the quote operators should work nicely.
perl -e '$foo=q/bar/;$bar=q/baz/; $baz=qq/$foo/; print qq/$foo $bar $baz\n/; print q/$foo $bar $baz/,qq/\n/;' bar baz bar $foo $bar $baz
That doesn't solve all the quoting issues, but does simplify some of them.
Yes. I've even done this before when I ran into the problem with a perl one-liner. Another solution I've used for perl-less situations is to create a bash function containing the original command, followed by a "$*". IOW, given: perl -e '$foo=join(" ",@ARGV); print "echo:\n\t$foo\n"' .. in bash you can say, function xyzzy { perl -e '$foo=join(" ",@ARGV); print "echo:\n\t$foo\n"' $* } .. which in most (all?) cases is just like saying, alias xyzzy='perl -e "\$foo=join(\" \",@ARGV); print \"echo:\\n\\t\$foo\\n\""' Putting the command in a function works just like making an alias with it but avoids having to deal with any messy quoting or escaping. This is a good general solution - it would have even worked with the example I gave - but my question was prompted by a desire to understand the quoting/escaping issues with bash. -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