0

I am presently writing an automated install script for Arch Linux, to simplify the install process for myself (in case my current installation of Arch goes belly up and I can't fix it myself), but the problem is that I don't know how to enter a newly-created user account and execute a command in it from a shell script. I know that running su - $USERNAME will log me into the $USERNAME account. The problem is that after running this command all further lines in the shell script are ignored.

4
  • su - $USERNAME -c <command> Mar 17 '16 at 10:56
  • 1
    Also please consider of using sudo to run command as different user Mar 17 '16 at 11:34
  • Also, FWIW, there are tons of backup tools/strategies that are likely to work better then your script, why are you re-inventing the wheel?
    – Panther
    Mar 17 '16 at 12:10
  • Firstly, because I have never used such tools, secondly because I would like others to be able to benefit from these scripts too. @LaurentiuRoescu your solution worked for me, if you want to write it up as an answer I will accept it.
    – Josh Pinto
    Mar 17 '16 at 12:36
2

Running a command as another user:

su - $USERNAME -c <command>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.