2

I am creating a script meant to be run as superuser that reads a file and runs a number of scripts on behalf of all users. The important bit is this:

sudo -u $user -H source /home/$user/list_of_commands

However, whether I encose the command with quotesor not, this fails with:

sudo: source /home/user/list_of_commands: command not found

I have even tried with the . bash builtin:

sudo: . /home/user/list_of_commands: command not found

Of course running source outside a sudo environment works. I thought there might be a PATH problem, and I tried to bypass it by providing the full path to source. However, I cannot find the executable: which source returns which: no source in (/usr/local/sbin:usr/local/bin:usr/bin). So I'm stuck.

How do I make a script source a file as a user?

1 Answer 1

2

source is a builtin not a command, use it with bash -c:

sudo -u $user -H bash -c "source /home/$user/list_of_commands"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.