Running bash function in command of su

Viewed 6851

In my bash script, I execute some commands as another user. I want to call a bash function using su.

my_function()
{
  do_something
}

su username -c "my_function"

The above script doesn't work. Of course, my_function is not defined inside su. One idea I have is to put the function into a separate file. Do you have a better idea that avoids making another file?

4 Answers
Related