在 bash 中,声明一个依赖于当前变量内容的别名

iXô*_*iXô 5 linux bash shell environment-variables

我想声明一个别名(在 my 中.bash_profile),它将在使用别名时使用变量的内容(值),而不是在定义时使用。例如,

alias goSomeWhere="cd $BASE/somewhere"
Run Code Online (Sandbox Code Playgroud)

$BASE定义别名时未设置,仅在使用时设置。但是,因为$BASE是在定义别名时(在登录时)计算的,所以goSomeWhere别名被解释为cd /somewhere.

如何延迟对变量的评估,直到执行别名?

Cyr*_*rus 6

更换都"通过'或前缀$使用\