0

I am learning bash. Now I would like to run a function specifying a user, like,

function bash_function() { rm -r "some_directory"; }
sudo -u user bash_function

Thank you very much.

mora
  • 2,217
  • 4
  • 22
  • 32
  • 2
    Related: http://stackoverflow.com/questions/9448920/how-can-i-execute-a-bash-function-using-sudo – user000001 Sep 07 '16 at 13:26
  • 2
    More likely, `bash_function` doesn't need to run as `user`, but some command in the body of the function does. Rewrite the function to use `sudo` where appropriate. – chepner Sep 07 '16 at 13:40
  • Thank you everyone. Thanks to comments above, function bash_function() { sudo -u "$1" rm -r "some_directory"; } may be a easiest way. – mora Sep 07 '16 at 13:52

0 Answers0