Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you set an environoment variable 1

Status
Not open for further replies.

ejaggers

Programmer
Feb 26, 2005
148
US
I want to set an env variable in a Linux shell, LOGx where x=1,2,3, or 4. If x was 1 last time then ++$x;

Shell: LOG=logname concat'ed with $x

I came u with a perl script to handle $lognum but how do I get ksh to see it; i.e.

#!/usr/bin/perl
my $logFH = '/home/informix/Primero/primero.cfg';
my $logFH = 'primero.cfg';

unless ( -s $logFH ) {
open(OFH,">$logFH");
print OFH '0';
close OFH;
}

open(IFH,$logFH);
chomp( my $lognum = <IFH> );
close IFH;
$lognum = ( ++$lognum > 4) ? 1 : $lognum;

open(OFH,">$logFH");
print OFH $lognum;
close OFH;
system("export LOGNUM=$lognum");
exit;
 
Hi

ejaggers said:
How do you set an environoment variable
From the environment.

The [tt]perl[/tt] script is a child process of [tt]ksh[/tt]. It has its own environment, which will live only while the child process is running. Child processes can not modify the parent's environment.

But while you write the $lognum to a file, just let [tt]ksh[/tt] set its environment variable from that :
Code:
run_perl_script_run && export LOGNUM="$( < primero.cfg )"

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top