If I need to, I can pass it through bash. I just don't know how (with the ability to get the values back).

You have sparked a fascinating discussion, making me wonder whether "only bash can parse a bash script"...

Meanwhile, you could get bash to do the work for you, I think, if you try the following steps:

perl -e '$env = `your_bash_script.file`; print $env,$/'
Maybe you want to redirect the output of that to a file. Note that the output will include everything in your current shell environment, along with everything declared by the bash script. If you also run a one-liner like this:
perl -e '$env = `bash -c env`; print $env,$/'
and compare that output to the one involving your bash script, you'll be able to "subtract out" the "ambient environment", and isolate the stuff that comes from the script.

There might be other ways to do the same thing, but this was the first one I found (and I'll confess it took several iterations to figure it out).

UPDATE: Just putting "env" at the end entails a simplistic assumption that the bash script will execute more or less linearly from top to bottom. But if there are multiple points in the script where processing could end under different conditions (and especially if more than one of these exit points qualifies as "success"), you would need to add the "env" command at every such point. Good luck with that...


In reply to Re: simulating bash by graff
in thread simulating bash by agaffney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.