In a bash script, I am trying to run a function which pass as parameter a command line. And so I am trying to pass a find
command as another user.
Instead of running straight the find
command, I have a function run-command
which basically run and output the command and the result. Nothing complex.
I am trying to run this command:
su - ${USER} -c '$(run-command find ${DIR} -name TEST* -exec rm -rf "{}" +)'
But it is failing, message error:
I am able to run find
command as another user as following:
- su - ${USER} -c '$(find ${DIR} -name TEST* -exec rm -rf "{}" +)'
- sudo -u ${USER} find ${DIR} -name "TEST*" -exec rm -rf "{}" +
It looks like I can not call a function of the script when I switch with su
command to another user.
- I want to continue my script as the current user after running this command line.
- I do not want to give special privilege to current user to run that command himself (nothing to modify in
/etc/sudoers
).
Thanks in advance for your help.