Score:-2

sudo . source_file command not found

it flag
. source_file

works.

sudo . source_file

doesn't work.

Is there a replacement command?

Score:3
vn flag

source (and the alias .) is a builtin command, not an executable, therefore sudo doesn't work directly.

However, you could run:

sudo bash -c 'source /full/path/to/source_file'

This would start a bash session as root, and source source_file under this session. The file source_file could of course contain any number of commands that are run when it is sourced, but the shell would exit immediately this is done.

Another useful option would be to run a bash subshell with sudo, and source source_file as the initial commands. This can be done in a number of ways.

You could include source_file as the init file for bash:

sudo bash --init-file /full/path/to/source_file

This would source source_file, but on the other hand your ~/.bashrc will NOT be sourced.

To get both the ~/.bashrc and the source_file, we need to create a temporary init file that bash can use:

echo "source ~/.bashrc; source /full/path/to/source_file" > /dev/shm/initfile.rc; sudo bash --init-file /dev/shm/initfile.rc

With this command, bash sources both ~/.bashrc and source_file in an interactive root shell (since it uses your newly created init file).

it flag
This is an exhaustive and sufficient answer.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.