Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

trouble when calling a shell script for setting an env var

0 views
Skip to first unread message

Paul Johnson

unread,
Jan 16, 2003, 3:19:20 PM1/16/03
to Konrad Foerstner, begi...@perl.org
On Thu, Jan 16, 2003 at 08:58:22PM +0100, Konrad Foerstner wrote:

> I need to get a value from an environment variable VALUE. This value is
> set by an shell script which location is stored in anonther environment
> variable called SCRIPT. So I first call the shell script by
>
> `. \$SCRIPT`;
>
> and extract then the value of VALUE by
>
> my $value = $ENV(VALUE);
>
> But something does not work, so $value is empty. As the shell script
> produces also an echo output I catch it by using
>
> my @output = `. \$SCRIPT`;
>
> I get this output correctly, but VALUE is still empty! I also tried also
>
> system(\$SCRIPT`);
>
> and
>
> `. /place/of/my/shellscript.sh`;
>
> Both don't have the wished effect.
>
> When I call the shell script in the shell and the start my perl script
> VALUE is set and available for my perl script.
>
> What is wrong?

Unfortunately, your understanding of processes. A child process cannot
alter the environment of its parent.

Take a look at Shell::Source on CPAN.

--
Paul Johnson - pa...@pjcj.net
http://www.pjcj.net

Konrad Foerstner

unread,
Jan 16, 2003, 2:58:22 PM1/16/03
to begi...@perl.org
He folks!

Todays problem:

I need to get a value from an environment variable VALUE. This value is
set by an shell script which location is stored in anonther environment
variable called SCRIPT. So I first call the shell script by

`. \$SCRIPT`;

and extract then the value of VALUE by

my $value = $ENV(VALUE);

But something does not work, so $value is empty. As the shell script
produces also an echo output I catch it by using

my @output = `. \$SCRIPT`;

I get this output correctly, but VALUE is still empty! I also tried also

system(\$SCRIPT`);

and

`. /place/of/my/shellscript.sh`;

Both don't have the wished effect.

When I call the shell script in the shell and the start my perl script
VALUE is set and available for my perl script.

What is wrong?

Konrad

Konrad Foerstner

unread,
Jan 16, 2003, 3:29:42 PM1/16/03
to begi...@perl.org

> > I need to get a value from an environment variable VALUE. This value is
> > set by an shell script which location is stored in anonther environment
> > variable called SCRIPT. So I first call the shell script by
> >
> > `. \$SCRIPT`;
> >
> > and extract then the value of VALUE by
> >
> > my $value = $ENV(VALUE);
> >
> > But something does not work, so $value is empty. As the shell script
> > produces also an echo output I catch it by using
> >
> > my @output = `. \$SCRIPT`;
> >
> > I get this output correctly, but VALUE is still empty! I also tried also
> >
> > system(\$SCRIPT`);
> >
> > and
> >
> > `. /place/of/my/shellscript.sh`;
> >
> > Both don't have the wished effect.
> >
> > When I call the shell script in the shell and the start my perl script
> > VALUE is set and available for my perl script.
> >
> > What is wrong?
>
> Unfortunately, your understanding of processes. A child process cannot
> alter the environment of its parent.
>
> Take a look at Shell::Source on CPAN.

Ah, okay! Thanks a lot!
Konrad

0 new messages