this variable should be available to other script
If you are brave, and insist on this approach, you can do this with an ugly dot-and-carry method. Assume that your perl script is embedded a wrapper shell (bash-like assumed) script like so:
cd /path/to/script ./myperlscript foo bar rat quux . ./newvar.sh ./myotherscript
Where your perl script 'myperlscript' contains (amongst whatever else it needs to do) something like the following:
#! /usr/local/bin/perl my %new_env = @ARGV; open OUT, '> newvar.sh' or die "cannot open newvar.sh for output: $!\n +"; print OUT "#! /bin/sh\n"; print OUT "export $_=$new_env{$_}\n" for keys %new_env; close OUT;
That is, the perl script writes the shell script that is the next command to be executed in the outer shell script. By the time ./myotherscript runs, the environment will have been sourced by the script that the perl script wrote beforehand.
But keep in mind that this is a maintenance nightmare, and those who come after you will not venerate your name.
- another intruder with the mooring in the heart of the Perl
In reply to Re: create environment variable at run time
by grinder
in thread create environment variable at run time
by sachin_chat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |