Your shell is interpreting the $HOME
variable in the heredoc, before the input reaches the su
shell. You need to escape the $
:
bash-3.2$ sudo su -l root <<EOF
> echo $HOME
> echo \$HOME
> EOF
/Users/kevin
/var/root
The real question is why does it work on your Linux box.