Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect STDERR to a variable [duplicate]

I have this code that produces an error, and it works to supress the STDOUT but it doesnt store the STDERR in the variable ERROR.

ERROR = $(memtester 900 1 > /dev/null)
like image 666
Aaron Avatar asked Mar 01 '17 23:03

Aaron


1 Answers

You can capture it like this:

error=$(memtester 900 1 2>&1 >/dev/null)

order of redirection operators is important here.

  • 2>&1 - redirects stderr to stdout
  • >/dev/null - redirects stdout to /dev/null
like image 122
anubhava Avatar answered Nov 15 '22 05:11

anubhava