Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There is a shell function add_book in my .zshrc. I need to invoke this function with sudo permission. But when I invoke sudo add_book I get the following error:

sudo: add_book: command not found

What can I do?

share|improve this question

2 Answers 2

You can run the program by getting root permission in advanced with this command:

sudo -i

Then run your command when it turns into root@hostname#

share|improve this answer
Not sure. I haven't tried it, but -i option stands for "interactive" and loads the TARGET user's profile. So if a normal user defines a custom command on his shell, -i simply ignores that and looks for commands available for root. I repeat, I haven't tried it! –  djechelon Nov 4 '12 at 13:20
# cat /tmp/moo 
function moo { echo moo; }
# unset moo
# type moo 
-bash: type: moo: not found
# sudo -u root bash -c 'source /tmp/moo; moo' 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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