?
Solved

Store the error output of a command in shell script

Posted on 2013-12-12
4
Medium Priority
?
260 Views
Last Modified: 2013-12-13
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.
0
Comment
Question by:MidwestTapes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 2000 total points
ID: 39715398
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
 

Author Comment

by:MidwestTapes
ID: 39716840
Yea that did the trick but before I close out I curious as to what the 2>&1 means/did.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39717019
It means: send error messages (2) to regular output  (&1)
0
 

Author Comment

by:MidwestTapes
ID: 39717037
Thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question