Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: backticks and quotation trouble in bash

by LanX (Canon)
on Dec 18, 2012 at 15:42 UTC ( #1009410=note: print w/ replies, xml ) Need Help??


in reply to Re^2: backticks and quotation trouble in bash
in thread backticks and quotation trouble in 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.


Comment on Re^3: backticks and quotation trouble in bash
Download Code
Re^4: backticks and quotation trouble in bash
by floobit (Initiate) on Dec 18, 2012 at 15:47 UTC
    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=="'
Re^4: backticks and quotation trouble in bash
by floobit (Initiate) on Dec 18, 2012 at 16:03 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-07-29 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls