Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

copying bash variables into a Perl script

by fionbarr (Friar)
on Jun 15, 2010 at 19:38 UTC ( [id://844923]=perlquestion: print w/replies, xml ) Need Help??

fionbarr has asked for the wisdom of the Perl Monks concerning the following question:

hi I need to run a Perl script which is kicked off by a bash shell script. I would like to define some directories in the bash script such that I can pick them up in the Perl script. I've looked around on Google and my Perl books but haven't found anything worthwhile. I would appreciate some ideas. Thanks
  • Comment on copying bash variables into a Perl script

Replies are listed 'Best First'.
Re: copying bash variables into a Perl script
by toolic (Bishop) on Jun 15, 2010 at 19:51 UTC
    Here are 2 ways:
    • pass them onto your Perl script command line
    • set environment variables in your bash script, then read them in your Perl script from %ENV
      Examples:

      pass them onto your Perl script command line

      $ perl -le'print $ARGV[0]' 'Hello, World!' Hello, World!
      $ FOO='Hello, World!' $ perl -le'print $ARGV[0]' "$FOO" Hello, World!

      set environment variables in your bash script

      $ FOO='Hello, World!' $ export FOO $ perl -le'print $ENV{FOO}' Hello, World!
      $ export FOO='Hello, World!' $ perl -le'print $ENV{FOO}' Hello, World!
      $ FOO='Hello, World!' perl -le'print $ENV{FOO}' Hello, World!

      Here is another but rather silly way: have the Perl script read the source of the bash script and extract the names and values of the bash variables.

      The only advantage I see of this approach over your suggestions is that the Perl script needs only to know the name of the bash script. It does not need to know either the number or the names of the bash variables.

      Paul

      i have a shell script and perl script in different paths i have exported a variable name in sh script and referencing it in perl script using %ENV. But still i get error as uninitialised value am i supposed declare the shell script path in anyway lik how we use "require" and "use" or is there any other way of coding it? please help me in getting the solution for it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://844923]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found