Store the error output of a command in shell script

I am able to store the output of a command when it completes successfully.
example

#!/bin/sh
createimage=$(aws ec2 create-image --instance-id i-bb68f5df --name ftp.b2b.backup.12-1 --no-reboot --description ftp.b2b.backup.test)
echo "$createimage"

script returns
{
    "ImageId": "ami-f5113e9c"
}

however when the command fails in the script the output is not being stored in the createimage variable.
MidwestTapesAsked:
Who is Participating?
 
MikeOM_DBACommented:
Try:
createimage=$(aws ec2 create-image --instance-id i-bb68f5df --name ftp.b2b.backup.12-1 --no-reboot --description ftp.b2b.backup.test  2>&1 )

Open in new window

0
 
MidwestTapesAuthor Commented:
Yea that did the trick but before I close out I curious as to what the 2>&1 means/did.
0
 
MikeOM_DBACommented:
It means: send error messages (2) to regular output  (&1)
0
 
MidwestTapesAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.