Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to change a script's environment after the script is already run, based on shell sourcing ?

by rjray (Chaplain)
on Sep 28, 2006 at 08:42 UTC ( [id://575308]=note: print w/replies, xml ) Need Help??


in reply to How to change a script's environment after the script is already run, based on shell sourcing ?

Assuming you have the filename ahead of time, just parse it yourself:

our $file = '/etc/profiles/bashrc.ora.v.10'; open my $fh, "< $file" or die "open: $!"; while (defined($_ = <$fh>)) { next unless /^export\s+([A-Za-z]\w+)=(.*)$/; $ENV{$1} = $2; } close($fh);

--rjray

  • Comment on Re: How to change a script's environment after the script is already run, based on shell sourcing ?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to change a script's environment after the script is already run, based on shell sourcing ?
by graff (Chancellor) on Sep 29, 2006 at 00:20 UTC
    That would probably work fine for a majority of cases, where the shell script for environment setup tends to be pretty simple and explicit. It's a good-enough solution when you know enough about the shell script to trust that it will work.

    But I can easily imagine (and have seen) examples where the value assigned to a relevant exported variable refers to some other shell variable that was set previously in the same file (and not necessarily exported), or is the output of some back-ticked command, or other arcane cleverness. For shell scripts like that, you really don't want this approach.

      True, but the original author hinted that the file contained only simple environment variables in the vein of ORACLE_SID and similar.

      There's probably a CPAN module already that handles the special cases and back-ticks, in fact...

      --rjray

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-25 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found