我正在创建一个脚本来检查 AWS Cli 版本并将其存储在变量中以便稍后使用。
#!/bin/bash
OS=$(uname -a)
AWS_CLI=$(aws --version)
echo echo "{\"changed\":false,\"kernal version\":\"$OS\",\"AWS CLI version\":\"$AWS_CLI\"}"
但输出如下所示。
{
"AWS CLI version": "",
"kernal version": "Linux ip-10-0-14-174 ... x86_64 x86_64 x86_64 GNU/Linux"
}
如何获取 bash 变量的 aws --version 值?
最佳答案
在我的 Centos 7 中,我需要选择 stderr:
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d " " -f1 | cut -d "/" -f2)
关于linux - 检查 bash 脚本上的 AWS cli 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68175838/