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 |