BASH:在echo期间替换变量内的变量

2 bash

我在评论中解释了我的问题:

VAR=
INS="Installing $VAR"

echo $INS   
.           # In each echo command I want to dynamically substitute
.           # the $VAR variable in the $INS variable. I want to do
echo $INS   # the substitution of the variable on echo command.
Run Code Online (Sandbox Code Playgroud)

这可能吗?

kev*_*kev 5

您需要一个功能才能优雅地完成工作.

say() {
    echo "Installing $INS"
}

INS=hello
say

INS=world
say
Run Code Online (Sandbox Code Playgroud)

或者就是这样:

say() {
    echo "Installing $@"
}

say hello

say world
Run Code Online (Sandbox Code Playgroud)