Issue
I have a certain value that a bunch of scripts/functions I run on my machine need access to, and it changes frequently. For context, it's the git tag of the current commit deployed to production of the primary app we work on, but that's not important. I've been automating it by setting it as a local variable within the context of my current shell, which has been nice, but any other shells I have open cannot access it. This is unfortunate because I often have multiple shells open and want this variable in all of them.
What would be the best way to pass this value around where every open shell can access it? I looked into setting it as an environment variable, but changing an environment variable does not affect its value in already open shells so that wouldn't work. And I could obviously update it in my .bashrc
but that would require re-running a source
command in every open shell and I'm lazy. What is the best way to share a value between Bash shells?
Solution
I like Redis for this - it is lightweight, and fast and accessible from any language (Python, bash, Perl, PHP, C/C++, Ruby) and across the network. It supports strings, sets, sorted sets, lists, queues, hashes, atomic integers and so on:
# Set variable to 10
redis-cli set fred 10
OK
# Retrieve variable
redis-cli get fred
"10"
Answered By - Mark Setchell Answer Checked By - Marilyn (WPSolving Volunteer)