Link to home
Start Free TrialLog in
Avatar of MidwestTapes
MidwestTapes

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of MikeOM_DBA
MikeOM_DBA
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MidwestTapes
MidwestTapes

ASKER

Yea that did the trick but before I close out I curious as to what the 2>&1 means/did.
It means: send error messages (2) to regular output  (&1)
Thank you