Hi all,
1. Is it possible to inline a sh/csh script from a Perl program.
I realize, I can run the shell script as,
system("Foo.sh") ;
but I want all the variables I set in my Perl program to be available
to Foo.sh.
Um, how do you mean that? If you mean the environment variables you
set in perl, they *are* available to Foo.sh:
testit.pl:
#!/usr/bin/perl
use strict;
use warnings;
$ENV{thisone} = "from perl";
system("./Foo.sh");
---------------------------------------------------------
Foo.sh:
#!/bin/sh
echo "$thisone"
---------------------------------------------------------
syscjm@sakura:~$ ./testit.pl
from perl
---------------------------------------------------------
If you mean you want to be able to access the perl script's variables
from the shell script, how about opening the shell as a pipe and
putting in the script as a here doc?
#!/usr/bin/perl
use strict;
use warnings;
my $an_interpolated_var = "from perl";
open (my $mysh, "|-", "sh") or die ("Couldn't start shell: $!");
print $mysh <<ENDIT;
echo "This is my shell":
echo "This is $an_interpolated_var"
echo "This is \$a_shell_var"
ENDIT
close ($mysh);
-----------------------------------------------------------
syscjm@sakura:~$ export a_shell_var="from the shell"
syscjm@sakura:~$ ./testit.pl
This is my shell
This is from perl
This is from the shell
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"