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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i set/read an environment variable in a script???

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
Hi all,

basicaly what i'm doing is writing a script that will check a environment variable periodically while running (looping)in the background (&)

i need to be able to set/change this variable with any script.

The variable name i have chosen to use is 'STATUS', which will have a number value of 0 - 2.

e.g.
#!/bin/sh
start of loop
check STATUS env var
if (0)
sleep 60
exit
elseif (1)
do something
sleep longer
exit
fi
go to start of loop



Hope this is clear, any help appreciated

JayBot!
"Always know what you say, but don't always say what you know!"
 
Just set the variable and export it. It should then be visible to all scripts.

STATUS=0;export STATUS

Greg.
 
Thanks,

But how can i read this variable into my script?
And any idears about how i can create a loop as described above?

Sorry for sounding a bit dunce, i have been programming for many years and in many languages but i am new to shell programming and the usual application of commands like 'do' and 'while' do not seem to work as expected in the shell.

any help would be appreciated!

JayBot
"Always know what you say, but don't always say what you know!"
 
Hi,

by exporting a variable you can make it's content visible to all sub-processes of the given process/shell, but not to a previously started script, waiting in the backgroud.

you will probably need some file to hold your status, or implement something more sophisticated for inter-process-communication like shared memory or the use of named pipes.

mbr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top