当命令中有反斜杠或命令被引用时,POSIX 标准中的什么阻止别名替换?
What in the POSIX standard prevents alias substitution when there is backslash in the command or the command is quoted?
我定义了一个这样的别名。
[user@centos ~]$ alias echo='echo aliased echo says: '
[user@centos ~]$ echo hi
aliased echo says: hi
为什么在有反斜杠或部分命令被引用时不会发生别名替换,如下所示?您能否通过在 http://pubs.opengroup.org/onlinepubs/9699919799/.
引用 POSIX 标准的相关部分来解释它
[user@centos ~]$ \echo hi
hi
[user@centos ~]$ ec\ho hi
hi
[user@centos ~]$ "echo" hi
hi
[user@centos ~]$ ec"ho" hi
hi
[user@centos ~]$ command echo hi
hi
[user@centos ~]$ command -v echo
alias echo='echo aliased echo says: '
引用http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
中的相关部分
2.3.1 Alias Substitution
After a token has been delimited, but before applying the grammatical
rules in Shell Grammar, a resulting word that is identified to be the
command name word of a simple command shall be examined to determine
whether it is an unquoted, valid alias name. However, reserved words
in correct grammatical context shall not be candidates for alias
substitution. A valid alias name (see XBD Alias Name) shall be one
that has been defined by the alias utility and not subsequently
undefined using unalias. Implementations also may provide predefined
valid aliases that are in effect when the shell is invoked. To prevent
infinite loops in recursive aliasing, if the shell is not currently
processing an alias of the same name, the word shall be replaced by
the value of the alias; otherwise, it shall not be replaced.
If the value of the alias replacing the word ends in a <blank>,
the shell shall check the next command word for alias substitution;
this process shall continue until a word is found that is not a valid
alias or an alias value does not end in a <blank>.
When used as specified by this volume of POSIX.1-2008, alias
definitions shall not be inherited by separate invocations of the
shell or by the utility execution environments invoked by the shell;
see Shell Execution Environment.
以上部分有没有什么原因导致的?
是的,有一些东西:unquoted这个词在“...确定它是否是一个不带引号的有效别名”。当引用命令词的任何部分时,这句话禁止别名替换。
shell 中有三种 引用机制:反斜杠、单引号和双引号。
我定义了一个这样的别名。
[user@centos ~]$ alias echo='echo aliased echo says: '
[user@centos ~]$ echo hi
aliased echo says: hi
为什么在有反斜杠或部分命令被引用时不会发生别名替换,如下所示?您能否通过在 http://pubs.opengroup.org/onlinepubs/9699919799/.
引用 POSIX 标准的相关部分来解释它[user@centos ~]$ \echo hi
hi
[user@centos ~]$ ec\ho hi
hi
[user@centos ~]$ "echo" hi
hi
[user@centos ~]$ ec"ho" hi
hi
[user@centos ~]$ command echo hi
hi
[user@centos ~]$ command -v echo
alias echo='echo aliased echo says: '
引用http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
中的相关部分2.3.1 Alias Substitution
After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name. However, reserved words in correct grammatical context shall not be candidates for alias substitution. A valid alias name (see XBD Alias Name) shall be one that has been defined by the alias utility and not subsequently undefined using unalias. Implementations also may provide predefined valid aliases that are in effect when the shell is invoked. To prevent infinite loops in recursive aliasing, if the shell is not currently processing an alias of the same name, the word shall be replaced by the value of the alias; otherwise, it shall not be replaced.
If the value of the alias replacing the word ends in a <blank>, the shell shall check the next command word for alias substitution; this process shall continue until a word is found that is not a valid alias or an alias value does not end in a <blank>.
When used as specified by this volume of POSIX.1-2008, alias definitions shall not be inherited by separate invocations of the shell or by the utility execution environments invoked by the shell; see Shell Execution Environment.
以上部分有没有什么原因导致的?
是的,有一些东西:unquoted这个词在“...确定它是否是一个不带引号的有效别名”。当引用命令词的任何部分时,这句话禁止别名替换。
shell 中有三种 引用机制:反斜杠、单引号和双引号。