Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: source a file in Linux using perl script

by perlfan (Vicar)
on Nov 30, 2020 at 18:20 UTC ( #11124408=note: print w/replies, xml ) Need Help??

in reply to source a file in Linux using perl script

Your execution environment inherits the environment set up via ~/.bash_profile. I recommend you not try to source that file in the script. If you need to access the environment and manipulate it, you do so via %ENV. Then anything you run under that perl process will inherit this environment. A child process can't affect the parent process's (e.g., bash shell) environment once the process is complete. In other words, you can't use a script or program to update the environment of the shell in a persistent way (after the perl script has exited).

If you wish to make CTC_HOME available as part of the environment in your script you can update %ENV in the code:

use strict; use warnings; local %ENV = %ENV; # NOTE: local is used here in case you wish to # restore the original %ENV in a different scope # of this script $ENV{CTC_HOME} = q{/Inf/work/}; # ... now "CTC_HOME" is available for all child # processes (via fork, system, ``, etc) of $0 (this script)

Given this idiom, you could then pass in CTC_HOME as a commandline argument or, better still, as a configuration file that you can then parse via Config::Tiny. That said, you could also just make sure the environment is set up as you wished via ~/.bash_profile before execution to avoid all of this. I am still not sure why you want to effect ~/.bash_profile. It almost seems like you're wishing to ensure an environment via command invoked via ssh. In this case, note that ssh has options that allow you to pass remote environmental viariables via the ssh command itself.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11124408]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-04-18 03:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found