1847178 Members
5314 Online
110263 Solutions
New Discussion

script variables

 
SOLVED
Go to solution
Ratzie
Super Advisor

script variables

I have a script that calls another script, which runs a cmd. I then take the exit variable and store it...
gzip -cxvf offline_backup.tar.bz2 -p --same-permissions -m --same-owner --overwrite
TAREXIT=${?}

I have done testing when the gtar exit's succesfully and not successfully.

How do I use TAREXIT in my original script?


I tried to do..

gzip -cxvf offline_backup.tar.bz2 -p --same-permissions -m --same-owner --overwrite
TAREXIT=${?}
export $TAREXIT

But I get an error...
/home/scripts/backup/uncompress_db.scr[45]: 2: is not an identifier
./test[175]: TAREXIT: Parameter not set.

I am doing these scripts in ksh
3 REPLIES 3
harry d brown jr
Honored Contributor
Solution

Re: script variables

You can have the calling program take the output from the called program and assign it to a variable, which would require the called program to ECHO the TAREXIT variable.

OR

write the TAREXIT variable to a file in the format of:
export TAREXIT

then have the calling program SOURCE (. ./thefilenameusedabove) thefilenamed usedabove.

OR

if it's not necessary to have the called script external, then put it into the calling program.

live free or die
harry
Live Free or Die
curt larson_1
Honored Contributor

Re: script variables

you use:

TAREXIT=${?}
exit $TAREXIT


in the call script

cmd
retcode=${?}
#retcode will now equal the value of TAREXIT

A. Clay Stephenson
Acclaimed Contributor

Re: script variables

You simply
export TAREXIT

But you should know that export works only in one direction: From Parent to Child process. Make sure that you are not trying to use a variable exported by a child process in a parent.
If it ain't broke, I can fix that.