Take the 2-minute tour ×
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.

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
1  
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
show 1 more comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.