Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 5
    $HOME isn't set by bash - Thanks, I didn't know that. Commented Jan 2, 2015 at 8:11
  • Look for strace in my answer. It shows that you don't need to build /bin/bash -l -c 'echo $HOME' command line yourself when using -i. Commented Jan 2, 2015 at 9:46
  • 1
    That sudo syntax threw an error on my machine. (su uses the -c option, but I don't think sudo does.) I had better luck with: HomeDir=$( sudo -u "$1" -H -s echo "\$HOME" ) Commented Oct 13, 2016 at 20:21
  • yeah, @palswim is right. Not sure about -S (I didn't need it, so I left it out), but -c doesn't work here, you need -s instead. Commented Jan 7, 2019 at 23:34