[英]sudo: command: command not found on CentOS 6
在bash 4.1.2
和Centos 6.10
(因为我们是怪物)。
sudo command vim
退货
sudo: command: command not found
我不明白为什么。 在bash 4.4.23
, Mac OS High Sierra
可以正常运行。 用谷歌搜索非常困难,因为人们使用“命令”作为他们正在谈论的各种命令的占位符。
我有一个名为vim
的函数(如下所示),从对vim的调用中删除command
不会像我期望的那样在bash 4.4和4.1上导致它失败。
我有一个功能,如果我无法写入文件,则可以自动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
}
我希望命令是必需的,因为否则vim
应该引用我所做的函数并称其为无穷大。 然而,不仅是它不是必需的,对CentOS的和Mac系统两种,而且它会导致功能失效的CentOS的盒子!
谁能解释这种行为?
有什么方便的bash更改日志,我可以看看它是否知道在bash 4.1之后才以某种方式实现“命令”吗?
sudo
需要一个可执行文件; command
(通常)是内置的Shell,而不是可执行文件,它修改了Shell执行查找的方式。 sudo vim
可以正常工作,因为sudo
不能运行shell函数或使用名为vim
的别名来vim
command vim
会提供给您的可执行文件。
macOS
实际上确实提供了一个shell脚本/usr/bin/command
(据我所知)似乎可以模拟内置的shell,同时可以补偿HFS +默认设置的不区分大小写。 内置command
会将其bash
在bash
,但可以从其他shell(或从运行其他命令的命令,如sudo
)获得。
POSIX要求实现该command
,尽管不一定是内置的shell。 为操作系统提供带command
的外壳程序可能就足够了。 (POSIX规范指出“命令实用程序很可能作为常规的内置程序提供。”,并继续列出了为什么command
中未列出command
一些原因,而其他必须内置的command
也未列出。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.