in reply to backticks and quotation trouble in bash

The alternative syntax for backticks in Bourne shell would be $( ... ):

host=$(ifconfig | perl -e ' while (<>) { $_ =~ /inet addr:(10.[\d.]+)/ +; $host = `nslookup $1`; }; $host =~ /name = ([\S]+)./; print $1;')

I'm not quite sure it's available in all Bourne-compatible shells, but it seems to work on the Debian Almquist shell so it's a fairly safe bet that it is.

BTW, you should be able to split that command into two with a temporary variable or so and avoid the problem:

ip=`ifconfig | perl -ne ' $_ =~ /inet addr:(10.[\d.]+)/ and print $1` host=`nslookup $ip | perl -ne '/name = ([\S]+)./; print $1;'`

Replies are listed 'Best First'.
Re^2: backticks and quotation trouble in bash
by Anonymous Monk on Jan 27, 2013 at 00:38 UTC

    The $( ... ) syntax for command substitution is not alternative, but is in fact the preferred one according to the POSIX standard.

    Backticks/backquotes have long been considered legacy and are deprecated: they are hard to read, and nesting and quoting are problematic.

    In the new and more readable form, nesting "just works" and quotes have their own context within the command substitution so it's not necessary to escape them.

    See the POSIX documentation for more details.