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.
相关问题
- How to get the return code of a shell script in lu
- $ENV{$variable} in perl
- Invoking Mirth Connect CLI with Powershell script
- Is it possible to pass command-line arguments to @
- Emacs shell: save commit message
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Launch interactive SSH bash session from PHP
- Can NOT List directory including space using Perl
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
:Given
it prints
The code can only handle simple files (for instance, it doesn't handle
if
statements orfoo=$(date)
). If you need something more complex, then writing a wrapper for your Perl script that sourcesenv.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
:where foo.real is your Perl script.
You can use arbitrarily complex shell scripts by executing them with the relevant shell, dumping their environment to standard output in the same process, and parsing that in perl. Feeding the output into something other than %ENV or filtering for specific values of interest is prudent so you don't change things like PATH that may have interesting side effects elsewhere. I've discarded standard output and error from the spawned shell script although they could be redirected to temporary files and used for diagnostic output in the perl script.
foo.pl:
foo.sh: export BAR=baz
Try this (unix code sample):
cd /tmp
vi s
vi t
chmod 777 s t
./t
ENV first call is :
ENV second call is : test
The trick is using the exec to source your bash script first and then calling your perl script again with an argument so u know that you are being called for a second time.