floobit has asked for the wisdom of the Perl Monks concerning the following question:
I'm having some difficulty using a perl one-liner within a bash program. This works fine:
ifconfig | perl -e ' while (<>) { $_ =~ /inet addr:(10.[\d.]+)/; $host = `nslookup $1`; }; $host =~ /name = ([\S]+)./; print $1;'However, this does not (bash complains about bad syntax, as if it's trying to parse the perl):
host=`ifconfig | perl -e ' while (<>) { $_ =~ /inet addr:(10.[\d.]+)/; $host = `nslookup $1`; }; $host =~ /name = ([\S]+)./; print $1;'`Some people on the internet recommend replacing my single quote with a double quote, but this does not help. I'm posting this in perl because it seems perl-specific. For example, this awk line works great, and has the same single-quote-within-backtick structure:
IP=`ifconfig | awk 'BEGIN { FS = ": " } { print $2 }'`Thoughts? No commentary on the fact that I should just write the whole program in perl, please. I would if I could.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: backticks and quotation trouble in bash
by LanX (Saint) on Dec 18, 2012 at 15:10 UTC | |
by floobit (Initiate) on Dec 18, 2012 at 15:26 UTC | |
by LanX (Saint) on Dec 18, 2012 at 15:42 UTC | |
by floobit (Initiate) on Dec 18, 2012 at 15:47 UTC | |
by Tommy (Chaplain) on Dec 18, 2012 at 16:29 UTC | |
by floobit (Initiate) on Dec 18, 2012 at 16:03 UTC | |
by CountZero (Bishop) on Dec 18, 2012 at 23:04 UTC | |
by roboticus (Chancellor) on Dec 18, 2012 at 15:43 UTC | |
|
Re: backticks and quotation trouble in bash
by Anonymous Monk on Dec 18, 2012 at 22:19 UTC | |
by Anonymous Monk on Jan 27, 2013 at 00:38 UTC |