How to evaluate a shell variable each time it's used

后端 未结 2 501
情歌与酒
情歌与酒 2020-12-21 04:12

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 tim

2条回答
  •  一整个雨季
    2020-12-21 04:41

    That's not possible. Use a function instead:

    my_date() {
        echo "today is $(date)"
    }
    
    # use it
    echo "$(my_date)"
    

    Note: This is bash syntax; your shell might use a slightly different syntax.

提交回复
热议问题