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

By neokrates, written on May 21, 2010

bash   snippet

Rate it
  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
Ad
Poll
  • Your skill as shell programmer is?

    • No skill (35%, 7 Votes)
    • FreeTime coder (acceptable) (25%, 5 Votes)
    • Developer (good) (15%, 3 Votes)
    • Novice (15%, 3 Votes)
    • Admin (very good) (10%, 2 Votes)
    • Guru (perfect) (0%, 0 Votes)

    Total Voters: 20

    Vote

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext
Most popular search terms:

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


[i] 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
 
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
    nope :(
SOCIAL
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • Blogosphere News
  • E-mail this story to a friend!
  • Furl
  • LinkArena
  • Live
  • MisterWong
  • Print this article!
  • StumbleUpon
  • Technorati
  • Webnews.de
  • YahooMyWeb

Leave a Reply