在while循环中打印当前迭代

问题描述 投票:0回答:1

我的脚本中有以下行,${snap[@]}数组包含我的ssh服务器列表。

      while IFS= read -r con; do
    ssh foo@"$con" /bin/bash <<- EOF
      echo "Current server is $con"
EOF
      done <<< "${snap[@]}"

我想在ssh成功运行时打印数组的当前迭代值,$con应该打印当前的ssh服务器->example@server。我该怎么做?

bash loops while-loop heredoc
1个回答
0
投票

喜欢这个:

while IFS= read -r con; do
    ssh "foo@$con" /bin/bash <<EOF
        echo "Current server is $con"
EOF
done < <(printf '%s\n' "${snap[@]}")
© www.soinside.com 2019 - 2024. All rights reserved.