zsh 有一个很好的简单的命令“=”扩展功能:
$ zsh
% echo =sed
/usr/bin/sed
% file =bugzilla
/usr/bin/bugzilla: Python script, ASCII text executable
%
参见http://zsh.sourceforge.net/Doc/Release/Expansion.html#g_t_0060_003d_0027-expansion
bash 有一些方便的等价物吗?
我能看到的最接近的是 type -tP <pgm>
,但还是有点拗口。
最佳答案
bash 不提供像 zsh 那样的任何扩展,但它确实有一些实用程序可以为您提供有关命令的信息:
command -v是一个 shell 内置命令,它将告诉您 shell 将如何调用作为参数传递的命令:
user@pc:~$ command -v ls
alias ls='ls --color=auto'
使用-V
(大写)会将字符串写入标准输出,指示在当前 shell 执行环境中 shell 如何解释参数
user@pc:~$ command -V ls
ls is aliased to `ls --color=auto'
which逐步执行 $PATH
环境变量并检查文件是否存在并给出找到的结果:
user@pc:~$ which ls
/bin/ls
user@pc:~$
whereis将搜索 $PATH
、手册页和源文件来查找应用程序文件:
user@pc:~$ whereis ls
ls:
/bin/ls
/usr/share/man/man1/ls.1.gz
user@pc:~$
关于bash 相当于 zsh 的 '=' 命令路径扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55278100/