I have a sh script that needs to be run as root, however it is run by the end user using sudo. How can I get the users home directory when ~/ points to /root when running with s
The user's home directory would be ~$SUDO_USER. You can use eval as follows:
~$SUDO_USER
eval
USER_HOME=$(eval echo ~${SUDO_USER}) echo ${USER_HOME}