Hello cellmates, I'm about to convert some Unix shell scripts into Perl but have come up against what to me is a baffling problem - bear with me as my scripting knowledge is limited! As the scripts I'm converting are part of a package there are some constraints that I'm having to work within. The problem is that the shell script runs 2 scripts to set up the required environment. To make future upgrades simple I would prefer to call these scripts as a subroutine (their contents change with each new release) rather than transcribe them into Perl. The small test I've done for this produced unexpected results. I make system calls to both scripts which appear to work. I then print the ENV hash table contents to a file. I was shocked to discover that the changes apparently made by these scripts are not present (No $ORACLE_HOME etc). If I call these scripts from the command line the changes are there. Moreover if I run my script after calling these routines from the command line everything is as I would want it. The noddy test code follows:-
#!/usr/bin/perl -w
#
use strict ;
use FileHandle ;
#
# SCALAR VARIABLES
#-----------------#
my $key = undef ;
my $opfile = 'xxrc_env_details' ;
my $result = 0 ;
my $script = 'xxrcenvtest' ;
my $value = undef ;
my $footer = "\n\t\t***** End of Report *****\n\n" ;
#
# F O R M A T T I N G
#-------------------#
format XXRC_TOP =
ENVIRONMENT Details for IHSLIVE
.
#
format XXRC =
@<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+<<<<<<<<
$key, $value
.
#
# P R O C E S S I N G
#---------------------#
#
print "\n\t\t*** $script S T A R T S ***\n" ;
#
$result = system(". /opt/bin/oraIHSLIVE.env") ;
#
print "\n\tRES :: $result\n" ;
if ($result) {
print "\n\t\tRes :: $result\n" ;
print "\n\t\tBombing Out (1)\n" ;
exit 122 ;
}
#
$result = system(". /opt/bin/fsw.env IHSLIVE") ;
#
if ($result) {
print "\n\t\tRes :: $result\n" ;
print "\n\t\tBombing Out (2)\n" ;
exit 123 ;
}
#
open XXRC, ">$opfile" or die "\n\tCanny Open $opfile :: $!\n" ;
#
# Formating code
#--------------#
select XXRC ;
STDOUT->format_top_name("XXRC_TOP") ;
STDOUT->format_name("XXRC") ;
foreach $key (sort keys %ENV) {
$value = $ENV{$key} ;
write or die "\n\tyou hivnae goat this richt min! :: $!\n" ;
}
#STDOUT->format_name("XXRC_2") ;
#write or die "\n\tyou hivnae goat this richt min! :: $!\n" ;
select STDOUT ;
print XXRC "$footer" or die "\n\tyou hivnae goat this richt min! :: $!
+\n" ;
close XXRC or die "Canny Close $opfile :: $!\n" ;
print "\n\t\t*** $script E N D S ***\n\n\n" ;
Can I expect such calls to produce the environment that I want or do I have to convert the shell script into Perl? Have I missed the point about the interaction between the shell environment and Perls?
Cheers,
Ronnie
2006-04-29 Retitled by planetscape, as per Monastery guidelines
Original title: 'Envoronment variables?'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.