alias slt=open -a "Sublime Text开发者_Python百科 2"
Doing slt /regular/file
works.
Doing sudo slt /etc/hosts
fails.
sudo: slt: command not found
What gives?
Aliases are only known to your local shell. They are substituted during interactive command input, and are not inherited by child shells. So sudo simply won't have it. You should use a shell script instead.
I managed to make root work. Just by modifying /root/.bashrc
alias sublime='/home/kervin/Software/Sublime-Text-2/sublime_text'
You must run it, to verify it.
source .bashrc
On restart the .bashrc runs automatically.
However, only "su -" and becoming root works, whereas using "sudo sublime" does not.
Any other ways to do that?
To get this to work, make an alias to sudo as 'sudo '. Then bash will expand your alias. For example,
$ alias sudo='sudo '
$ alias h='head'
$ h /etc/shadow
head: cannot open '/etc/shadow' for reading: Permission denied
$ sudo h /etc/shadow
root:!:15725:0:99999:7:::
daemon:*:15630:0:99999:7:::
精彩评论