0

I have an install script that sets some environment variables. To run the script I have to use the source command.

The script has to be run as sudo because the environment variables need to be set for the root account.

The problem is you can't execute "sudo source installScript". How do I execute "source installScript" as sudo, or root user?

I already tried "sudo /bin/bash ./installScript".

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by jbennet
0

In order to accomplish that, you'll need a root shell. If your root account is enabled, you can authenticate yourself with 'su', otherwise just run "sudo bash" (or whatever shell you prefer) and enter your password.

Once you've obtained the root shell, you can run the source command and proceed with the install.

0

One thing to remember about 'sudo su' is that it's not a 'login shell' by default. If you use 'sudo su -l' ('sudo su -' for short) then you'll inherit all of the root user's environment variables, like the path and such.

Just curious though, why would you need to source the install script? If you're only running the one script, you shouldn't need to export any variables to your shell. Especially if you're running it with sudo, because in that environment, you're root just for that installscript, and then you're out and anything that was sourced doesn't matter.

Thanks!
-G

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.