我正在嘗試運行以下命令,但收到錯誤的替換錯誤。
for i in ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}; do aws eks describe-cluster --name $i | jq '.cluster.tags."Dev-Ver"'; done
請參閱下面的錯誤訊息
bash: ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}: bad substitution
有什么想法可能導致這種情況嗎?
謝謝。
uj5u.com熱心網友回復:
不要for用來讀行。
我建議將管道的輸出通過aws|tr|grep管道傳輸到一個while read回圈中:添加行延續和換行符以提高可讀性
aws eks list-clusters --query 'clusters' --output text \
| tr '\t' '\n' \
| grep dev-shark \
| while IFS= read -r line; do
aws eks describe-cluster --name "$line" \
| jq '.cluster.tags."Dev-Ver"'
done
uj5u.com熱心網友回復:
最后一個管道沒有設定任何操作“| dev-shark”,您是否要過濾文本“dev-shark”,那么代碼應該是
for i in ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}; do aws eks describe-cluster --name $i | jq '.cluster.tags."Dev-Ver"'; done
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/452802.html
