Hello fellow monks,

Quick description: in bash, you can write functions to help with larger scripts, and these are stored in the bash environment somehow (ie they can persist between scripts if "source" is used). How do I set up those functions in the environment from Perl?

Long version: I'm trying to create a stop-gap perl script for automating the build process at the company I work for. The existing build script is done in a pair of bash shell scripts, called from cygwin under windows. I'm running Perl 5.8.0 (Win32 installer version).

The existing build scripts use a two step approach. The first script is designed to be used as a .bash_profile script, or "source"'d in order to import the environment variable definitions into the shell environment. It also defines a few (*cough* evil *cough*) bash script functions that then become available to subsequent scripts called in the same shell.

The second script is the top level script that traverses the source directory tree and builds each of the modules in turn. It extensively uses the bash functions defined by the first script. I'd rather not rework every lower level build script just now (at least until I can rewrite the whole sorry mess).

The big problem is that in order to invoke a shell script, I have to call the interpreter directly. As two separate scripts, this means that they are executed in separate subshells, meaning the environment variables defined in the first script don't carry over.

I can replicate the environment variables using perls $ENV{} facility, but is it possible to use that same interface to add bash function definitions to the environment as well? This would allow me to dispense with the first script entirely, and just call the actual build script.

Many thanks in advance for any perl wisdom provided!
Mike


In reply to Creating bash functions using perls $ENV interface by tid

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.