I have a script that checks if Java version 8 is installed on my system. If not, the script installs it. Also once it makes sure that correct java version is installed it checks if $JAVA_HOME variable is set properly.
I am doing this by adding JAVA_HOME path to my /etc/environment file.
Everything till here works.
In the next step however, when I try to reload the /etc/environment file using source command, it does not load the new file.
I believe this is due to user running the script. I am running the script as root user. However I need to run source /etc/environment as non-root user and the have rest of the commands run as root.
I have tried sudo with the -u and su with -u -c commands, however this has not worked for me. Any pointers to how this could be done would be great help. Thanks
sudo. This way you're sure not to execute any command as root "by mistake". Note that the script will still ask for your password only once, since, after the first sudo command, sudo remembers your password for 15 minutes (by default). – Malte Skoruppa Apr 10 '19 at 13:12sudoto gain rights for the user. And running from root, you shouldn't need to enter password. – Soren A Apr 10 '19 at 13:18