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.
In reply to backticks and quotation trouble in bash by floobit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |