X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Message-ID: <4864FF51.91A5D351@dessent.net>
Date: Fri, 27 Jun 2008 07:55:13 -0700
From: Brian Dessent <brian@dessent.net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: sourcing a perl script on cygwin
References: <435f371f0806270051g7734f46ai9be6649011a05cbe@mail.gmail.com> 	 <435f371f0806270055p7555331dt18cd8c868c7e208@mail.gmail.com> 	 <435f371f0806270057j2800bea2xbc430867110f62a8@mail.gmail.com> 	 <4864D40F.E6FCF336@dessent.net> 	 <435f371f0806270504h3c4d18d3m1ff03bb06010daad@mail.gmail.com> 	 <4864DAD9.5EFC8601@dessent.net> <435f371f0806270736t9ca6411k41aa87337b181a27@mail.gmail.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes
Reply-To: cygwin@cygwin.com
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

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/

