Here’s a way to use variables in both bash and perl.
From Perl
- Start with a config file, we’ll call it ‘conf.ph’:
#!/usr/bin/perl %vars = ( HOME => '/home/gba', NAME => 'greg a' );
- from there we can load ‘conf.ph’ into any of our perl scripts
#!/usr/bin/perl require 'conf.ph';
- load its variables
#!/usr/bin/perl require 'conf.ph'; print "my name is: " , $vars{'NAME'} , "\n";
from bash
- using the same conf.ph we create a primer script to load the perl variables into the environment:
#!/usr/bin/perl include "conf.ph"; while ( my ($key, $value) = each(%vars) ) { $ENV{$key} = $value; } - we can then execute our shell script from with-in our primer script
#!/usr/bin/perl include "conf.ph"; while ( my ($key, $value) = each(%vars) ) { $ENV{$key} = $value; } system("/bin/myname.sh"); - /bin/myname.sh:
#!/bin/sh echo "my name is $NAME"
Advertisement