我有一个heredoc需要调用主脚本中的现有变量,并设置自己的变量以供后续使用。类似于这样:
count=0
ssh $other_host <<ENDSSH
if [[ "${count}" == "0" ]]; then
output="string1"
else
output="string2"
fi
echo output
ENDSSH
那样做是行不通的,因为“output”没有被设置为任何值。
我尝试使用这个问题中的解决方案:
count=0
ssh $other_host << \ENDSSH
if [[ "${count}" == "0" ]]; then
output="string1"
else
output="string2"
fi
echo output
ENDSSH
这也不起作用。$count 没有被扩展,所以 $output 被设置为 "string2"。
我如何使用一个 heredoc,同时扩展来自父脚本的变量,并设置它自己的变量?
count=0
的初始化。 - codeforester