简体   繁体   English

如何在 bash 的 aws cli 命令中传递变量?

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

I am unable to pass a variable in the tag-user cli command.我无法在 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=Used for SSO A=用于单点登录

passing the value of A to the below CLI :将 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"}]"

This is the error I get:这是我得到的错误:

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

This worked:这有效:

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

That is, using the following:也就是说,使用以下内容:

[
    {
        "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