Set variable to contain stderr or stdout (redirect error to out stream)

By neokrates, written on May 21, 2010

bash   snippet

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 251 views
Rate it
Ad
Poll
  • Which virtualization is used on your Enterprise?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

One-liner: set variable to contain stderr or stdout (redirect error to out stream)

Use 2>&1.

Example: Firefox may complain that it has not all packages it needs, capture what it complains about:

> firefoxSays=$(firefox --version 2>&1 ) ; echo $firefoxSays

💡REMARK: you can grep for particular problem, i.e. does Firefox complain about not having libdbus?:

> firefoxSays=$(firefox --version 2>&1 | grep libdbus ) ; echo $firefoxSays
Be Sociable, Share!
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: -1 (from 1 vote)
0 votes 'YES'  1 votes 'NO'
TAGS
No tags for this post.
RELATED
Pages
Posts
SOCIAL
Be Sociable, Share!

Leave a Reply