bash 相当于 zsh 的 '=' 命令路径扩展?

标签 bash zsh

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/

相关文章:

bash - shell 脚本 : intersperse comments between multiline logical operators

linux - 我的终端在哪个操作系统中运行?

bash 命令在 while 循环中重定向标准输入(使用 sed)

bash - 在同一行 Bash 中回显多个变量

linux - 如何根据另一个 zip 的内容创建子 zip?

Bash:有什么方法可以提取该字符串的第一部分吗?

zsh 临时禁用函数中的别名

terminal - 如何在 VSCode 终端中将光标移动到行首?

bash - 我如何学习如何在 bash 中正确引用?

bash - 现有的 fd 是否总是被复制为输入和输出?