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".

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.

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

Thanks got it working now.

marked as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.