title: Bash script - store stderr in a variable
body: <p>I'm writing a script to backup a database. I have the following line:</p>
  
  <pre><code>mysqldump --user=$dbuser --password=$dbpswd  \
     --host=$host $mysqldb | gzip &gt; $filename
  </code></pre>
  
  <p>I want to assign the stderr to a variable, so that it will send an email to myself letting me know what happened if something goes wrong. I've found solutions to redirect stderr to stdout, but I can't do that as the stdout is already being sent (via gzip) to a file. How can I separately store stderr in a variable $result ?</p>