Related to a similar problem I’m having:
zsh not re-computing my shell prompt
Is there any way to define a shell variable such that its value is calculated each time its called?
for example if I do:
my_date="today is $(date)"
The value in my_date would be:
today is Thu Aug 9 08:06:18 PDT 2012
but I want the date to be executed each time my_date is used. In the linked post, somebody recommended putting the value in single quotes:
my_date='today is $(date)'
but never evaluates anything, it just stays literally at $(date).
I’m using zsh 5.0.0
That’s not possible. Use a function instead:
Note: This is bash syntax; your shell might use a slightly different syntax.