Check AWS cli version on bash script

Viewed 1040

I am creating a script to check AWS Cli version and store it in a Variable to use it later.

#!/bin/bash

OS=$(uname -a)
AWS_CLI=$(aws --version)

echo echo "{\"changed\":false,\"kernal version\":\"$OS\",\"AWS CLI version\":\"$AWS_CLI\"}"

But the output is shown as following.

{
    "AWS CLI version": "",     
    "kernal version": "Linux ip-10-0-14-174 ... x86_64 x86_64 x86_64 GNU/Linux"
}

How can I get the value of aws --version to bash variable?

1 Answers

In my Centos 7, I need to pick the stderr:

AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d " " -f1 | cut -d "/" -f2)
Related