aceroraptor has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to figure out how include within a Perl script a .ksh script containing library functions that I wish to invoke through the use of back quotes in my Perl program. Regards
  • Comment on How to include bash functions file in Perl?

Replies are listed 'Best First'.
Re: How to include bash functions file in Perl?
by ikegami (Patriarch) on May 19, 2010 at 17:57 UTC

    You didn't specify what interface your script provides to allow other processes to access its functions. You're not even clear in which language your library uses. (bash or ksh?) Helping you use an unspecified interface is not really possible.

    Update: Well, you could do

    $ cat lib function greet() { echo 'Hello World!' } $ bash --rcfile lib -i -c greet Hello World! $ perl -e'system(bash => ( "--rcfile" => "lib", -i, -c => "greet" ))' Hello World!

      Sorry, I am a forum novice. Thanks your example did the trick. I wanted to make use of existing functions in a bash script. The particular function renamed for backup purposes existing log files. Below is the corrected problem area:

      my $sysTestLib="$HOME/bin/test/library/libsystemtest.ksh"; # Systest +libraries my $libFunc; # Systest Libray function variable if (-e $RESULTS) { $libFunc="libHandleFileName -f $RESULTS"; # System Test Library +Function $renameRes = system(bash => ("--rcfile" => "$sysTestLib", -i, -c => + "$libFunc" ) ); }
        sub text_to_sh_lit { my ($s) = @_; $s =~ s/'/'\\''/g; return "'$s'"; } my $cmd = ( join ' ', map text_to_sh_lit($_), libHandleFileName => ( -f => $RESULTS, ) ); $renameRes = system( bash => ( "--rcfile" => $sysTestLib, -i, -c => $cmd, ) );
Re: How to include bash functions file in Perl?
by ww (Archbishop) on May 19, 2010 at 17:16 UTC