passing arguments to a shell script from a perl script

D

doni

Hi,

Is there anyway can I pass arguments to a shell (bash) script from
within a perl script and execute the shell script.

The reason I want to call a shell script is that I want to export
environmental variables. Since, we can't do it from a perl script, I
wanted to write the environmental variables in a shell script and
execute it.

Can anyone let me know how can I do this in perl.

Thanks,
doni
 
S

smallpond

Hi,

Is there anyway can I pass arguments to a shell (bash) script from
within a perl script and execute the shell script.

The reason I want to call a shell script is that I want to export
environmental variables. Since, we can't do it from a perl script, I
wanted to write the environmental variables in a shell script and
execute it.

Can anyone let me know how can I do this in perl.

Thanks,
doni

Code called by system inherits the perl environment.
Try this:
perl -e '$ENV{PATH} .= ":/new/path"; system "echo \$PATH";'
 
M

Martijn Lievaart

Hi,

Is there anyway can I pass arguments to a shell (bash) script from
within a perl script and execute the shell script.

The reason I want to call a shell script is that I want to export
environmental variables. Since, we can't do it from a perl script, I
wanted to write the environmental variables in a shell script and
execute it.

Just set values in %ENV and your child process will inherit them. No need
for this complicated workaround.

HTH,
M4
 
J

Josef Moellers

aaah said:
Hi

You can actually actually indeed do this from within a perl script.
You can also set environment variables from within perl. I'm sure
you will get a few responses on this one as there are various ways,
the simplest way would be to do:
______________
my $script_to_execute = "script_name" ;
my $parameters = "one two three" ;
my $shell_call = $script_to_execute . " $parameters" # note the
space

system($shell_call)
______________

You're not doing anything with the environment other than passing it
along implicitly.

You'd have to modify %ENV.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top