sudo: source: command not found
The problem is that source
is a bash build-in command (not a program - like ls
or grep
). I think one approach is to login as root and then execute the source command.
sudo -s
source /etc/bash.bashrc
The problem is not that source
is a shell builtin command. The fact that it is is what's actually throwing you the command not found
error, but it doesn't mean it would work if it were.
The actual problem is how environment variables work. And they work like this:
every time a new process is started, if nothing happens, it inherits the environment of its parent. Due to this, using a subshell (e.g. typing bash
inside a bash instance) and looking at the output of env
should give similar results than its parent.
However, due to how sudo
works (as stated in its manpage), sudo tries to strip the environment of the user and create a "default" environment for the supplanting user, so that the command run is run as if the user who invoked it had been the calling user (which is the expected behaviour), and thus running nautilus as sudo nautilus
should open a folder at the /root
folder, and not /home/yourusername
.
So:
Doing something like sudo source script.sh
and then sudo command
, even if it worked, it wouldn't be successful at setting any variable to the later sudo command
.
In order to pass environment variables, you can either tell sudo to preserve the environment (via the -E
switch; and having appropriate permissions in your sudoers file) and/or setting it for the command as sudo VAR1=VALUE1 VAR2=VALUE2 command
.
Using bash process substitution you can do:
source <(sudo cat /etc/bash.bashrc)