Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6182949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:17:02+00:00 2026-05-24T01:17:02+00:00

I want to call env.sh from my_perl.pl without forking a subshell. I tried with

  • 0

I want to call “env.sh ” from “my_perl.pl” without forking a subshell. I tried with backtics and system like this –> system (. env.sh) [dot space env.sh] , however wont work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:17:03+00:00Added an answer on May 24, 2026 at 1:17 am

    Child environments cannot change parent environments. Your best bet is to parse env.sh from inside the Perl code and set the variables in %ENV:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    sub source {
        my $name = shift;
    
        open my $fh, "<", $name
            or die "could not open $name: $!";
    
        while (<$fh>) {
            chomp;
            my ($k, $v) = split /=/, $_, 2;
            $v =~ s/^(['"])(.*)\1/$2/; #' fix highlighter
            $v =~ s/\$([a-zA-Z]\w*)/$ENV{$1}/g;
            $v =~ s/`(.*?)`/`$1`/ge; #dangerous
            $ENV{$k} = $v;
        }
    }
    
    source "env.sh";
    
    for my $k (qw/foo bar baz quux/) {
        print "$k => $ENV{$k}\n";
    }
    

    Given

    foo=5
    bar=10
    baz="$foo$bar"
    quux=`date +%Y%m%d`
    

    it prints

    foo => 5
    bar => 10
    baz => 510
    quux => 20110726
    

    The code can only handle simple files (for instance, it doesn’t handle if statements or foo=$(date)). If you need something more complex, then writing a wrapper for your Perl script that sources env.sh first is the right way to go (it is also probably the right way to go in the first place).

    Another reason to source env.sh before executing the Perl script is that setting the environment variables in Perl may happen too late for modules that are expecting to see them.

    In the file foo:

    #!/bin/bash
    
    source env.sh
    
    exec foo.real
    

    where foo.real is your Perl script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a method say success(message) of javascript from android activity. I
Along the same lines as this question , I want to call acts_as_reportable inside
my application want to call a method of a class that is from another
I want to call a C subroutine from Java. I'm using JNI. I have
I want to call Java class methods from a cpp file that receives call
I want to call a process via a python program, however, this process need
I want to call a webservice using Zend_Soap_Client. This is the relevant code: $params
I am trying to call my linux executable from shell script. Before calling this
I can't change a value from a class. This is my problem : #!/usr/bin/env
I'm stuck with this, I need to call a Java Function from c/c++. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.