Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Assigning output of unix command to a variable

by almut (Canon)
on Dec 23, 2009 at 01:25 UTC ( #814034=note: print w/replies, xml ) Need Help??

in reply to Assigning output of unix command to a variable

Not really sure why it doesn't get past the '|' (works fine here), but what looks suspicious is the @nodes=(<LIST>); as this reads everything from the second line onwards into an array which you never use in the loop. As a result, there would only be one call to nslookup with $_ holding the first line of the input file. Not sure if that's intended.

Independently of that, you probably want to escape the $2 in the awk command, because backticks do interpolate variables... i.e.

my $nodename=`nslookup $_ | awk -F Name: '{ print \$2 }'`;

Replies are listed 'Best First'.
Re^2: Assigning output of unix command to a variable
by ksermas (Initiate) on Sep 04, 2012 at 18:53 UTC
    Thank you very much. You were right. As soon as I eacaped the '$' it worked perfectly!!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://814034]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-12-11 15:33 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (305 votes). Check out past polls.