1

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?

2
  • You haven't used $AWS_CLI anywhere? Commented Jun 29, 2021 at 9:17
  • @RamanSailopal, sorry. I have updated the script Commented Jun 29, 2021 at 9:34

1 Answer 1

3

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

AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d " " -f1 | cut -d "/" -f2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.