sudo: 命令:在 CentOS 6 上找不到命令
sudo: command: command not found on CentOS 6
MVCE:
在 bash 4.1.2
、Centos 6.10
(因为我们是怪物)。
sudo command vim
returns
sudo: command: command not found
我不明白为什么。在 bash 4.4.23
、Mac OS High Sierra
上它按预期工作。 google 这是非常困难的,因为人们使用 "command" 作为他们正在谈论的各种命令的占位符。
实际问题:
我有一个名为 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 "" || ( -w $(dirname "") && ! -f "" ) ]]; then
# \vim or 'vim' only escape aliases, not functions
command vim ""
else
#this 'command' isn't required! It won't loop forever without it.
sudo env HOME="$HOME" command vim -u $HOME/.vim/vimrc ""
fi
}
我希望命令是必需的,否则 vim
应该引用我创建的函数并无限调用它自己。但是,不仅在CentOS和Mac系统上不需要,而且在CentOS box上也会导致功能失效!
谁能解释这种行为?
是否有方便的 bash 变更日志我可以查看以了解 "command" 是否在 bash 4.1 之后才以某种方式实现?
sudo
需要一个可执行文件; command
(通常)是一个 shell 内置的,而不是可执行文件,它修改 shell 执行查找的方式。 sudo vim
可以正常工作,因为 sudo
不能 运行 一个 shell 函数或使用一个名为 vim
的别名隐藏 command vim
会给你的可执行文件。
macOS
实际上 确实 提供了一个 shell 脚本 /usr/bin/command
它(据我所知)似乎模拟了 shell 内置,同时补偿 HFS+ 默认的不区分大小写。内置 command
会在 bash
中隐藏它,但它可以从其他 shell 中获得(或从 运行 其他命令的命令中获得,例如 sudo
).
POSIX 要求实现 command
,但不一定作为 shell 内置。为 OS 提供内置 command
的 shell 可能就足够了。 (POSIX 规范声明 "The command utility is most likely to be provided as a regular built-in.",并继续列出 command
未列在 必须 的其他命令中的一些原因内置。)
MVCE:
在 bash 4.1.2
、Centos 6.10
(因为我们是怪物)。
sudo command vim
returns
sudo: command: command not found
我不明白为什么。在 bash 4.4.23
、Mac OS High Sierra
上它按预期工作。 google 这是非常困难的,因为人们使用 "command" 作为他们正在谈论的各种命令的占位符。
实际问题:
我有一个名为 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 "" || ( -w $(dirname "") && ! -f "" ) ]]; then
# \vim or 'vim' only escape aliases, not functions
command vim ""
else
#this 'command' isn't required! It won't loop forever without it.
sudo env HOME="$HOME" command vim -u $HOME/.vim/vimrc ""
fi
}
我希望命令是必需的,否则 vim
应该引用我创建的函数并无限调用它自己。但是,不仅在CentOS和Mac系统上不需要,而且在CentOS box上也会导致功能失效!
谁能解释这种行为?
是否有方便的 bash 变更日志我可以查看以了解 "command" 是否在 bash 4.1 之后才以某种方式实现?
sudo
需要一个可执行文件; command
(通常)是一个 shell 内置的,而不是可执行文件,它修改 shell 执行查找的方式。 sudo vim
可以正常工作,因为 sudo
不能 运行 一个 shell 函数或使用一个名为 vim
的别名隐藏 command vim
会给你的可执行文件。
macOS
实际上 确实 提供了一个 shell 脚本 /usr/bin/command
它(据我所知)似乎模拟了 shell 内置,同时补偿 HFS+ 默认的不区分大小写。内置 command
会在 bash
中隐藏它,但它可以从其他 shell 中获得(或从 运行 其他命令的命令中获得,例如 sudo
).
POSIX 要求实现 command
,但不一定作为 shell 内置。为 OS 提供内置 command
的 shell 可能就足够了。 (POSIX 规范声明 "The command utility is most likely to be provided as a regular built-in.",并继续列出 command
未列在 必须 的其他命令中的一些原因内置。)