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.

Say I have these two in my .zshrc:

alias sudo='nocorrect sudo'
alias boot27='grub-reboot 4 && reboot'

boot27 gives boot27: command not found. If I change the alias to 'nocorrect sudo ' or just 'sudo ', it works, but then other things like mkdir give nocorrect: command not found.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Just to clarify, you run sudo boot27 and get boot27: command not found because since sudo is an alias, bash stops scanning for aliases and does not recognize boot27 as one. As discussed here, one way of dealing with this is adding a space at the end of the alias definition.

Adding the space allows bash to recognize boot27 but the problem now is that your root account is not set to use zsh so sudo starts a bash shell instead. nocorrect is a zsh thing, bash has no idea what it is so it complains.

The simplest way to fix this would be to set root's shell to /bin/zsh:

sudo chsh

Then set your alias with the space:

alias sudo='nocorrect sudo '

Your boot27 alias has another problem though. I assume you run it as sudo boot27, the shell will read the alias and expand that to:

sudo grub-reboot 4 && reboot

So, it will run grub-reboot as root but it will run reboot as a normal user. What you want is either to change your alias to

alias boot27='grub-reboot 4 && sudo reboot'

and run it as sudo boot27, or to change your alias to

alias boot27='sudo grub-reboot 4 && sudo reboot'

and run it without sudo, just boot27.

share|improve this answer
    
Thanks, that helped. I have privileges to reboot as normal user, so I think I'll just leave it as is. –  Mike Roll Jun 9 '13 at 11:15
    
@terdon I've got a problem with this approach. I've detailed it in a question here, but basically this approach doesn't seem to work for me (while alias sudo='sudo ' works, as does alias sudo='nocorrect sudo'). Have you got any suggestions? –  Mike H-R May 3 at 13:53
    
@MikeH-R I posted an answer to your question. The issue is already addressed in my answer here, you need to change the sudo shell to zsh. –  terdon May 3 at 14:03

Your Answer

 
discard

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.