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.
~$ cat test.sh
output:
#!/usr/bin/bash
su -c "whoami" user
su -c "echo $HOME" user
~$ sudo ./test.sh
output:
user
/root
Why does the first 'su' command seem to run as 'user' but the second seems to run as 'root'?