Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Call perl script and capture values in bash.

by MacScissor (Acolyte)
on Sep 18, 2012 at 07:36 UTC ( #994221=perlquestion: print w/replies, xml ) Need Help??
MacScissor has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys! I have a bash script that calls a perl script. The perl script generates several values and saves them in variables. I need these values seperated from each other for use in the bash script, so I can't just capture the STDOUT. Any ideas? Thanks in advance!
  • Comment on Call perl script and capture values in bash.

Replies are listed 'Best First'.
Re: Call perl script and capture values in bash.
by choroba (Chancellor) on Sep 18, 2012 at 07:38 UTC
    If you are not able to parse the output to find the variables (which should be possible - can you show an example values?), you can save each variable to its own file and then retrieve the values from the files.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thank you for your fast reply! The perl script generates yesterdays date, saves it in $day $month and $year and prints these 3 variables. I can use this date as one string, that is no problem. But the perl script also has the variable $counter which is also printed. The final output looks like this:
      print "Backup date: $day\.$month\.$year\n"; print "$counter files have been successfully saved.\n";
      I need to use the date and the $counter value in bash.
        You can save the output to a bash array to easily access the values:
        out=($( date=${out[2]} counter=${out[3]}
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Parse output like ...
        print "counter=$counter files have been successfully saved.\n";
        In bash capture value assign after "counter=" string..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994221]
Approved by Ratazong
[SuicideJunkie]: That's a dumb comparison. If you want to compare equivalent things, you should ask about battery+motors vs fuel tank+engine+ transmission.
[pryrt]: Are you sure?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-08-22 18:54 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (339 votes). Check out past polls.