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
  • 51,052
  • 3
  • 17
  • 28

1 Answers1

1

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
  • 257,635
  • 38
  • 339
  • 400
Armali
  • 16,557
  • 13
  • 53
  • 152