1

In my .bashrc I'm setting a bash variable to the output of a script

export FOO=`/home/jist/tools/lookup1.pl`

This works great except that the output of that script can change during the day (mainly depending on if I'm on the company's VPN or not). So when I do something with the variable, I want it to re-execute the script and get the updated value. I have no idea how to do this? Can someone please help?

Thanks in advance.

Jistanidiot
  • 54,334
  • 4
  • 18
  • 29

1 Answers1

2

As described in a comment by William:

Make it a function emitting a refreshed value on stdout instead of a variable and always access it as $(FOO)

That means:

# create the function: put this in your .bashrc
FOO() { /home/jist/tools/lookup1.pl "$@"; }

# use the function and store its output: do this whenever you want the current result
currentFooResult=$(FOO)

# or, to just print the result to stdout:
FOO
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Armali
  • 18,255
  • 14
  • 57
  • 171