Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently I learned you can enable sudo for custom aliases as follows:

alias sudo='sudo ' # note: the space is required!

The reason this works is the following:

If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.

My question is: is there any way to enable sudo with custom functions too?

share|improve this question
what do you mean by custom fuctions? can you give one example of what kind of customization u want to make? – pradeepchhetri Mar 26 '12 at 7:30
Here’s an example of a custom function: function foo() { id; id; } I’d like to be able to enter sudo foo to have the function be executed as root. – Mathias Bynens Mar 26 '12 at 7:32
serverfault.com/questions/177699/… does that help? – Legolas Mar 26 '12 at 11:20
@Legolas Thanks, looks like this question is a duplicate of that one. Good catch! – Mathias Bynens Mar 26 '12 at 11:27
@MathiasBynens: The solution marked in the link provided by Legolas is not working in my case. – pradeepchhetri Mar 26 '12 at 13:04

Your Answer


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

Browse other questions tagged or ask your own question.