Is there any way that I can pass a Function from one user to another user?
For example, I have a small Bash script that I execute as Root:
#!/bin/bash
user_func(){
whoami
exit
}
su vagrant -c 'user_func'
However, the user_func Function isn't defined for the Vagrant user, only for Root, and can't be executed.
My other option would be to have multiple lines of
su vagrant -c 'cmd1'
su vagrant -c 'cmd2'
, etc
Or, execute multiple commands ex: su vagrant -c 'cmd1; cmd2; cmd3;', but I'd prefer to not have the excess, especially when attempting to execute more than 5 commands as the Vagrant user.
Is it possible to pass a Function to another user from within the same script (ex. not creating a script on disk as a different user and then executing that generated script)? Or is there another option that I am overlooking?