如何将 AWS CLI 的输出保存在变量中?

Mat*_*rix 3 amazon-web-services aws-cli

我想将 AWS CLI 的输出保存在一个变量中并在另一个 AWS CLI 中使用该变量,我所做的如下:

taskarn= aws ecs list-tasks --cluster  mycluster --service-name "myService" --region "eu-west-1" --output text | grep "arn" | tr -d '"'

echo  $taskarn;  //empty
aws ecs stop-task --cluster mycluster --task $taskarn --region "eu-west-1"
Run Code Online (Sandbox Code Playgroud)

当我回显 $taskarn 时,它是空的。

任何帮助,将不胜感激。

Mat*_*rix 7

我使用了以下命令,它工作正常:

taskarn=$(aws ecs list-tasks --cluster  mycluster --service-name "myservice" --region "eu-west-1" | grep "arn" | tr -d '"')
echo  $taskarn;

aws ecs stop-task --cluster mycluster --task $taskarn --region "eu-west-1"
Run Code Online (Sandbox Code Playgroud)