/usr/bin/test 中通常有一个测试,该测试位于路径中主目录中的测试之前。你可以通过输入命令来解决这个问题which test
编辑:正如 Alok Singhal 在下面的评论中指出的那样,test
也是 bash shell(以及其他一些 shell)中内置的命令之一,如果您使用的是 bash,那么another内置 shell 命令,type
,不仅可以向您展示哪些test
将被执行(即使它是内置的 shell 并且在文件系统上不可用),而且它隐藏了所有测试版本。例如,如果 /home/pat/bin 位于 /usr/bin 之前:
$ type -a test
test is a shell builtin
test is /home/pat/bin/test
test is /usr/bin/test
所以,输入type -a <cmdname>
弄清楚什么是非常有用的,不仅是要执行什么,而且是要执行什么not被处决。通过显示完整路径,它还允许您使用剪切和粘贴(在大多数终端程序中)来选择和执行正确的程序,即使您决定不重命名它。 (其他 shell 也有类似的别名功能。)
作为旁白,man type
不会为您提供任何有用的信息type
bash shell 命令,因为它不是一个独立的程序。man bash
确实描述了它,因为它是内置于 bash shell 中的——但是该文档中大量使用了字面词“type”,因此如果您正在寻找有关该文档的信息,滚动到底部是最快的。type
命令。
EDIT2:正如 hek2mgl 指出的那样,如果您在执行命令时遇到困难,则 hash 命令也很有用。特别是,如果您创建了一个与其他程序同名的程序,并且您已经运行了其他程序,则您的脚本可能无法运行,即使它位于路径中的第一个:
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ echo echo Hi there! > bin/python
$ chmod 700 bin/python
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ hash -r # Clear the hash for this instance of bash
$ python
Hi there!
$ rm bin/python
$ python
bash: /home/pat/bin/python: No such file or directory
$ hash -r
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>