Is there a way to set env variable for certain number of seconds and then reset. I have a script that reads the env variable. If it is set, script should exit. Basically I am trying to build a snooze algorithm. eg. It keeps on sending messages as it receives it. However sometimes I need to snooze them for say t seconds, during these t seconds it would buffer all incoming messages and when timer t expires, send the buffer contents. My approach is to use an
if [ $MY_ENV=set ]
then
buffer
fi
However this env variable must not be shell specific. It should be for every user logged in from different locations on the same machine.
Regardless of the timing part, there's no way to set a variable in the environment of an already-running process from outside that process.
You need to use the file system for this. If it's user-specific, it can be a file in the user's home directory, for example.