簡體   English   中英

如何在 bash 的 aws cli 命令中傳遞變量?

[英]How can I pass a variable in aws cli command in bash?

我無法在 tag-user cli 命令中傳遞變量。

A=$(aws iam list-user-tags --user-name user --query 'Tags[].{Key:Key,Value:Value}' | grep -B2 "Description" | grep Value | awk -F ":" '{print $2}' | tr -d '",'| awk '$1=$1')
aws iam list-user-tags --user-name user --query 'Tags[].{Key:Key,Value:Value}' | grep -B2 "Description" | grep Value
        "Value": "Used for SSO",

A=用於單點登錄

將 A 的值傳遞給以下 CLI:

aws iam tag-user --user-name azure-sso-user --tags "[{"Key": "own:team","Value": "test@test.com"},{"Key": "security","Value": "Service"},{"Key": "comment","Value": "$A"}]"

這是我得到的錯誤:

Error parsing parameter '--tags': Invalid JSON:
[{Key: own:team,Value: test@test.com},{Key: security,Value: Service},{Key: own:comment,Value: Used

這有效:

aws iam tag-user --user-name user --tags '[{"Key": "own:team","Value": "test@test.com"},{"Key": "security","Value": "Service"},{"Key": "own:comment","Value": "'"$A"'"}]'

也就是說,使用以下內容:

[
    {
        "Key": "own:team",
        "Value": "test@test.com"
    },
    {
        "Key": "security",
        "Value": "Service"
    },
    {
        "Key": "own:comment",
        "Value": "'"
        $A
        "'"
    }
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM