1

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?

2 Answers 2

0

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#

1
  • 1
    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! Nov 4, 2012 at 13:20
0
# 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' 
moo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .