I need to do something like this
- Set a unix variable with a default value.
- Run a shell script which reads that variable and process it.
- Upon processing it may or may not change the value of that variable.
Run this script every hour and ensure that the value of this variable now is the value set by last run of this script.
I am mostly looking for how to setting and retaining value. I did the following and it didn't work.
export last_build="hello"
source .bashrc
Then in my script which processes this variable
echo $last_build
export last_build="hello again"
echo $last_build
When I run this script, I get something like
hello
hello again
When I run second time, I am expecting the output to be
hello again
hello again
but it sill gives same output as the first run.
cron, or is it supposed to be run in your current interactive (login) shell? You can store variable settings in a file and use the dot.(orsource) command to read that file. And you can run some other script that modifies what's in the file. You could have a cron job that is run every hour that updates the file. And every time you run a program (script) that needs the environment variable, you could have the script read that file.for f in *; do printf -v "$f" %s "$(<"$f")"; done), easy to modify, easy to save.exportonly exports to your own subprocesses. The namespace is not more global, or more persistent, than that.