passing arguments to a shell script from a perl script

passing arguments to a shell script from a perl script

am 07.12.2007 20:44:57 von 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

Re: passing arguments to a shell script from a perl script

am 07.12.2007 21:05:26 von AAAH

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)
______________
Hope the above helps.
cheers


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Beta 6
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Re: passing arguments to a shell script from a perl script

am 07.12.2007 21:44:19 von smallpond

On Dec 7, 2:44 pm, doni wrote:
> 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";'

Re: passing arguments to a shell script from a perl script

am 07.12.2007 22:26:07 von Martijn Lievaart

On Fri, 07 Dec 2007 11:44:57 -0800, doni wrote:

> 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