[英]sudo: command: command not found on CentOS 6
on bash 4.1.2
, Centos 6.10
(because we're monsters). 在
bash 4.1.2
和Centos 6.10
(因为我们是怪物)。
sudo command vim
returns 退货
sudo: command: command not found
I don't understand why. 我不明白为什么。 on
bash 4.4.23
, Mac OS High Sierra
it works as expected. 在
bash 4.4.23
, Mac OS High Sierra
可以正常运行。 It is very difficult to google this as people use "command" as a placeholder for various commands they are talking about. 用谷歌搜索非常困难,因为人们使用“命令”作为他们正在谈论的各种命令的占位符。
I have a function (seen below) named vim
, taking the command
out from its calls to vim doesn't cause it to fail, like I'd expect, on both bash 4.4 and 4.1. 我有一个名为
vim
的函数(如下所示),从对vim的调用中删除command
不会像我期望的那样在bash 4.4和4.1上导致它失败。
I have a function to automatically sudo vim if I can't write to file: 我有一个功能,如果我无法写入文件,则可以自动sudo vim:
vim() {
#only good for auto-sudo. delete if no sudo privileges.
if [[ "$#" -ne 1 ]]; then
command vim "$@"
#cases: if we can write to the file, or the file doesn't exist but we can make new files in that dir
elif [[ -w "$1" || ( -w $(dirname "$1") && ! -f "$1" ) ]]; then
# \vim or 'vim' only escape aliases, not functions
command vim "$1"
else
#this 'command' isn't required! It won't loop forever without it.
sudo env HOME="$HOME" command vim -u $HOME/.vim/vimrc "$1"
fi
}
I expect command to be required, since otherwise vim
should refer to the function I made and call itself ad infinitum. 我希望命令是必需的,因为否则
vim
应该引用我所做的函数并称其为无穷大。 However, not only is it not required, on both the CentOS and Mac systems, but also it causes the function to fail on the CentOS box! 然而,不仅是它不是必需的,对CentOS的和Mac系统两种,而且它会导致功能失效的CentOS的盒子!
Can anyone explain this behavior? 谁能解释这种行为?
Is there a convenient bash changelog I can look at to know if "command" somehow wasn't implemented until after bash 4.1? 有什么方便的bash更改日志,我可以看看它是否知道在bash 4.1之后才以某种方式实现“命令”吗?
sudo
expects an executable; sudo
需要一个可执行文件; command
is (usually) a shell built-in, not an executable, that modifies how the shell performs its lookup. command
(通常)是内置的Shell,而不是可执行文件,它修改了Shell执行查找的方式。 sudo vim
would work fine, because sudo
can't run a shell function or use an alias named vim
that shadows the executable that command vim
would give you. sudo vim
可以正常工作,因为sudo
不能运行shell函数或使用名为vim
的别名来vim
command vim
会提供给您的可执行文件。
macOS
actually does provide a shell script /usr/bin/command
which (as far as I can tell) appears to simulate the shell built-in while compensating for the case-insensitivity that HFS+ defaults to. macOS
实际上确实提供了一个shell脚本/usr/bin/command
(据我所知)似乎可以模拟内置的shell,同时可以补偿HFS +默认设置的不区分大小写。 The built-in command
will shadow it in bash
, but it would be available from other shells (or from commands that run other commands, like sudo
). 内置
command
会将其bash
在bash
,但可以从其他shell(或从运行其他命令的命令,如sudo
)获得。
POSIX requires that command
be implemented, though not necessarily as a shell built-in. POSIX要求实现该
command
,尽管不一定是内置的shell。 Providing a shell with command
as a built-in is probably sufficient for the OS. 为操作系统提供带
command
的外壳程序可能就足够了。 (The POSIX spec states "The command utility is most likely to be provided as a regular built-in.", and proceeds to list some reasons why command
isn't listed among the other commands that must be built-ins.) (POSIX规范指出“命令实用程序很可能作为常规的内置程序提供。”,并继续列出了为什么
command
中未列出command
一些原因,而其他必须内置的command
也未列出。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.