[英]I added aliases to user ~/.bashrc but “sudo -u user -i 'alias_name'” still reports “command not found”?
As a trivial example, in user foo's ~/.bashrc there is an alias; 作为一个简单的例子,在用户foo的〜/ .bashrc中有一个别名;
alias ll='ls -l'
Using sudo I can see the alias is set; 使用sudo我可以看到别名已设置;
bar@laptop:~$ sudo -u foo -i alias ll
alias ll=`ls -l'
But, I can't actually use the alias; 但是,我实际上不能使用别名;
bar@laptop:~$ sudo -u foo -i ll
-bash: ll: command not found
Commands that are bash functions work, OK. 作为bash函数的命令工作正常。 Is there a way to get the aliases to work also? 有没有办法让别名也起作用?
Try: 尝试:
alias sudo='sudo '
http://www.shellperson.net/using-sudo-with-an-alias/ http://www.shellperson.net/using-sudo-with-an-alias/
There is a great example of how to do this in the Archlinux wiki . 在Archlinux维基中有一个很好的例子。 Add the follwoing to your .bashrc 将以下内容添加到.bashrc中
alias sudo="sudo "
Don't ask me why it works. 不要问我为什么会这样。 I've scoured my man pages looking for this without luck, but it's never failed me yet. 我已经仔细搜索了我的手册页,但没有运气,但它从来没有让我失望过。
> sudo ll
total 60
drwxr-xr-x 2 brice users 4096 Feb 4 16:17 classes
drwxr-xr-x 3 brice users 4096 Mar 6 21:48 Desktop
drwx------ 6 brice users 4096 Mar 28 21:32 Downloads
drwx------ 25 brice users 4096 Mar 29 21:20 Dropbox
drwxr-xr-x 2 brice users 4096 Mar 11 20:27 scripts
drwxr-xr-x 2 brice users 4096 Mar 19 21:59 tmp
make sure you add 确保你添加
alias sudo='sudo '
then go ahead and add your custom alias ... for eg. 然后继续添加您的自定义别名...例如。 if regular command is 如果常规命令是
sudo rm ~/qwerty/removethis.txt
alias for above command will look like 上面命令的别名看起来像
alias your_custom_alias='sudo rm ~/qwerty/removethis.txt'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.