http://www.perlmonks.org?node_id=1009393


in reply to backticks and quotation trouble in bash

It's a bash-quoting problem, since you can't nest backticks! ...`nslookup $1`...!

But there is a Perl solution: try qx or even system within perl to avoid disambiguation.

Cheers Rolf

Replies are listed 'Best First'.
Re^2: backticks and quotation trouble in bash
by floobit (Initiate) on Dec 18, 2012 at 15:26 UTC

    If it was a bash problem, why does the awk example work? Also, the tools you gave me are ways of calling bash from perl. I'm having trouble calling perl from bash.

      again ...qx/nslookup $1/ ... should do.

      > why does the awk example work?

      no nested backticks?

      > are ways of calling bash from perl

      exactly, thats the ill thing about your construct, your calling perl from bash to call a system command.

      Cheers Rolf

      UPDATE:

      > No commentary on the fact that I should just write the whole program in perl, please. I would if I could.

      LOL. This is a Perl help board, if you're not interested to learn our solutions you should consider hiring someone who does the tricky things for you.

        Thanks, I see it now. You have answered me perfectly.
        Unfortunately, it's more a restriction that "all my programs be in bash" for maintainability by other admins who potentially don't know perl. Using perl like I am here is a bit of a stretch, but it seems silly to use 6 pipes with alternating awk and sed lines when this is more readable and flexible, especially because the whole line can be commented as "get the hostname using DNS". Alas.

      floobit:

      Because the awk example, as mentioned by LanX doesn't try to nest backticks.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.