Redirect STDERR to a variable [duplicate] Redirect STDERR to a variable [duplicate] shell shell

Redirect STDERR to a variable [duplicate]


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