passing arguments to a shell script from a perl script

Discussion in 'Perl Misc' started by doni, Dec 7, 2007.

  1. doni

    doni Guest

    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
    doni, Dec 7, 2007
    #1
    1. Advertising

  2. doni

    smallpond Guest

    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";'
    smallpond, Dec 7, 2007
    #2
    1. Advertising

  3. 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
    Martijn Lievaart, Dec 7, 2007
    #3
  4. aaah wrote:
    > 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.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
    Josef Moellers, Dec 10, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Heimes
    Replies:
    0
    Views:
    580
    Christian Heimes
    Feb 27, 2008
  2. jay
    Replies:
    7
    Views:
    232
    Chad Perrin
    May 3, 2007
  3. moongeegee

    execute a shell script in a shell script

    moongeegee, Dec 3, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    230
    Ben Morrow
    Dec 4, 2007
  4. oldyork90
    Replies:
    10
    Views:
    326
    Jorge
    Sep 27, 2008
  5. Yogi
    Replies:
    1
    Views:
    414
    Peter Makholm
    Sep 13, 2012
Loading...

Share This Page