我有以下shell脚本 -
AWSZONE="central"
ENVIRONMENT="staging"
REMOTE_HOSTS_central_staging="172.31.7.59,172.31.3.151
NAME="REMOTE_HOSTS_${AWSZONE}_${ENVIRONMENT}"
echo "Using following agents: ${NAME}"
执行时我得到以下输出 -
Using following agents: REMOTE_HOSTS_central_staging
虽然我想获得输出 -
Using following agents: 172.31.7.59,172.31.3.151
我的语法有什么问题?
答案 0 :(得分:2)
将回声更改为
echo "Using following agents: ${!NAME}"
它应该没问题。
答案 1 :(得分:1)
试试这个:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
<强>输出:强>
AWSZONE="central"
ENVIRONMENT="staging"
REMOTE_HOSTS_central_staging="172.31.7.59,172.31.3.151"
NAME="REMOTE_HOSTS_${AWSZONE}_${ENVIRONMENT}"
eval "echo Using following agents: \$${NAME}"
如果你使用bash,你也可以使用@ LarsErik的答案。它被称为 Indirect Expansion