当我运行which命令时,它什么也没显示。
我运行了所有这些,但没有一个给出输出。
$ which /tool/
$ which RED*.pdf
$ which anime
$ which -a anime
$ info which
$ which -a
$ which -a Downloads
$ which Downloads
$ which doc
$ which media
$ which /media
$ which
$ su -
# which
# which doc
# logout
$ which --help
Illegal option --
Usage: fusrfbinfwhich [-a] args
$ which info
/usr/bin/info
$ which help
$ which cd
$ info which
$ which -a info
/usr/bin/info
$ which -a
$ which -a list.txt
Run Code Online (Sandbox Code Playgroud)
来自man which:
NAME
which - locate a command
SYNOPSIS
which [-a] filename ...
DESCRIPTION
which returns the pathnames of the files (or links) which would be executed
in the current environment, had its arguments been given as commands in a
strictly POSIX-conformant shell. It does this by searching the PATH for
executable files matching the names of the arguments. It does not follow
symbolic links.
Run Code Online (Sandbox Code Playgroud)
我不希望which给出任何输出 - 正如man页面所说,您需要一个作为命令的文件名。
尝试运行which ls。
可能是您想知道命令在哪里- 为此您需要 whereis。
$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
Run Code Online (Sandbox Code Playgroud)
就我而言,myscript.sh工作正常 buy which(nor whereis) 没有返回任何输出:
$ which myscript.sh
$
Run Code Online (Sandbox Code Playgroud)
来自which手册:
描述
which返回将在当前环境中执行的文件(或链接)的路径名,其参数在严格符合 POSIX 的 shell 中作为命令给出。 它通过在 PATH 中搜索与参数名称匹配的可执行文件来实现此目的。它不会规范化路径名。
我修复了它,将~(波形符) 更改为$HOMEon $PATH:
$ which myscript.sh
$
Run Code Online (Sandbox Code Playgroud)
现在还whereis -l显示我添加的文件夹。
有关和 之间的区别的更多信息,请参阅此答案。~$HOME