title: su commands in a script executed as root seem inconsistent
body: <p>I'm trying to understand how to run commands from my user account in a script with root privileges. I've got this test script and the output is confusing me.</p>
  
  <p>~$ cat test.sh</p>
  
  <p><strong>output</strong>:</p>
  
  <pre><code>#!/usr/bin/bash
  su -c "whoami" user
  su -c "echo $HOME" user
  </code></pre>
  
  <p>~$ sudo ./test.sh</p>
  
  <p><strong>output</strong>:</p>
  
  <pre><code>user
  /root
  </code></pre>
  
  <p>Why does the first 'su' command seem to run as 'user' but the second seems to run as 'root'?</p>