On 06/07/2010 04:56 PM, Bob Proulx wrote: > Matthew Woehlke wrote: >> How should bash interpret escapes in constructs like "`...`"? > > The quoting rules for backticks are complex enough that the entire > construct has long been replaced with a completely different one. I > strongly suggest that instead of struggling to get the backtick syntax > quoted satisfactorily that you use $(...) instead. The rules there > are much more reasonable.
I agree with Bob that $() is much nicer than ``. But if you care about portability, such as for Solaris /bin/sh, then you are forced to use ``. And unfortunately, if you care about portability, then you must never use embedded "" inside `` inside "", because not all shells follow the POSIX rules on that construct. POSIX requires that you use \" inside "``", because it states that "`" has undefined behavior (some older shells let the first unquoted " terminate the ``, even if there wasn't a matching `). It is always possible to write `` constructs that do not require "" nesting, by using a temporary variable. Besides, this also works around existing buggy shells (thankfully not bash) that mishandle signals arriving in the middle of ``, where the bad shells then proceed to execute the outer command with an empty string in the place of the `` instead of aborting the outer command. That is: echo "`echo \"a b\"`" ends up as echo "" in some buggy shells, but: tmp=`echo "a b"` echo "$tmp" will never execute the second echo if the first one was interrupted. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature