试图理解“别名|”的含义一些命令”语法
Trying to understand meaning of 'alias | some-command" syntax
这里alias
命令的管道是什么意思?
$ alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
这是一个(不可移植的)hack,让 GNU which
尝试表现得更像 type
。
用于显示外部命令位置和别名、函数等的 bash 内置工具称为 type
。当使用别名(或 shell 函数)调用时,它将发出其定义:
$ type ls
ls is aliased to `ls --color=auto'
因为which
是一个外部命令,它无法知道别名...除非它们是在标准输入上输入的:
$ alias # we have some aliases defined...
alias ls='ls --color=auto'
alias some-other-alias='whatever'
$ which ls # but which doesn't know about them...
/usr/bin/ls
$ alias | which --read-alias ls # *unless* we feed the definitions to it via stdin
alias ls='ls --color=auto'
/usr/bin/ls
正如您在上面看到的,which --read-alias
搜索它的标准输入(假设是别名列表)以查找似乎与相关命令匹配的别名定义,并在其输出中发出该定义。它从 shell-builtin alias
命令的输出中获取这些定义,该命令在不带参数调用时发出它们。
这仍然是次等的,当你知道你的shell是bash时,你应该使用type
代替。不像which
, type
了解 shell 函数;它知道缓存的 PATH 查找;它保证在任何安装 bash 的地方都可用(不像 GNU which
,默认情况下在具有 non-GNU 用户空间工具的平台上不可用,例如 MacOS 或 FreeBSD);它可以完成 shell 内部的所有操作,无需生成任何外部软件。
这里alias
命令的管道是什么意思?
$ alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
这是一个(不可移植的)hack,让 GNU which
尝试表现得更像 type
。
用于显示外部命令位置和别名、函数等的 bash 内置工具称为 type
。当使用别名(或 shell 函数)调用时,它将发出其定义:
$ type ls
ls is aliased to `ls --color=auto'
因为which
是一个外部命令,它无法知道别名...除非它们是在标准输入上输入的:
$ alias # we have some aliases defined...
alias ls='ls --color=auto'
alias some-other-alias='whatever'
$ which ls # but which doesn't know about them...
/usr/bin/ls
$ alias | which --read-alias ls # *unless* we feed the definitions to it via stdin
alias ls='ls --color=auto'
/usr/bin/ls
正如您在上面看到的,which --read-alias
搜索它的标准输入(假设是别名列表)以查找似乎与相关命令匹配的别名定义,并在其输出中发出该定义。它从 shell-builtin alias
命令的输出中获取这些定义,该命令在不带参数调用时发出它们。
这仍然是次等的,当你知道你的shell是bash时,你应该使用type
代替。不像which
, type
了解 shell 函数;它知道缓存的 PATH 查找;它保证在任何安装 bash 的地方都可用(不像 GNU which
,默认情况下在具有 non-GNU 用户空间工具的平台上不可用,例如 MacOS 或 FreeBSD);它可以完成 shell 内部的所有操作,无需生成任何外部软件。