This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sourcing a perl script on cygwin


Florin Barbalau wrote:

> I understand that I can call a shell script from a perl script by
> using the command:
> 
>  exec("shell_script_name");
> 
> but when proceeding this way I don't have the environment variables
> that were set in the perl script. Is there anther way to call the
> shell script so that the shell child receives them?

A simple testcase shows that this does work:

$ cat parent.pl
#!/usr/bin/perl -w

$ENV{'SOMEVAR'} = 'this value set in parent.pl';
exec("child.sh");

$ cat child.sh
#!/bin/sh

echo "SOMEVAR = $SOMEVAR"

$ ./child.sh
SOMEVAR = 

$ ./parent.pl
SOMEVAR = this value set in parent.pl

Whatever is happening in your case therefore is not because the
variables are not being inherited, but due to something else -- for
example your ~/.bashrc could contain commands to set variables,
clobbering the inherited values.  If that's the case then either modify
the startup files to not clobber the vars if they're already set, or
inhibit the shell from reading startup files with --norc and/or
--noprofile.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]