in reply to Re: backticks and quotation trouble in bash
in thread backticks and quotation trouble in bash

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.

  • Comment on Re^2: backticks and quotation trouble in bash

Replies are listed 'Best First'.
Re^3: backticks and quotation trouble in bash
by LanX (Saint) on Dec 18, 2012 at 15:42 UTC
    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.

        In bash, you can't nest backticks, but you can nest the newer, more flexible "$()" construct:

        echo "$( command arg arg '$( nested_command arg arg )' )"
        --
        Tommy
        $ perl -MMIME::Base64 -e 'print decode_base64 "YWNlQHRvbW15YnV0bGVyLm1lCg=="'
      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.
        So how will the other admins maintain the Perl part of your bash-script? It will not be more readable for someone who does not know Perl and they might indeed prefer 6 pipes, awk and sed.

        Wouldn't it be better to write a little Perl-script with well defined in-and-output and use that as a "black box" kind of building block?

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics
Re^3: backticks and quotation trouble in bash
by roboticus (Chancellor) on Dec 18, 2012 at 15:43 UTC

    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.