问题描述
在我的问题的第一部分,我将提供一些背景信息作为一个
服务给社区。第二部分包含实际问题。
第一部分
假设我' ve创建了以下别名:
alias ls ='ls -r'
/ pre>
我知道如何使用以下
方式临时unalias(即覆盖此别名):
1)命令的完整路径名:
/ bin / ls
2)命令替换:
$(which ls)
3)命令内置:
命令ls
4)双引号:
ls
5)单引号:
'ls'
6)反斜杠字符:
\ls
案例1是明显的,情况2只是一个变体。案例3中的内置命令被设计为忽略shell函数,但显然它也可以用于规避别名。最后,案例4和5与:
和:
第二部分
以下是问题:为什么案例6(通过说
\ls
覆盖别名)
考虑引用该词?根据这个问题的样式,我正在寻找对官方文档的引用。
文档说,反斜杠只能转义以下
字符,而不是单引号和双引号,引用一个
字符序列。 ::
(BTW,不是下一个字符跟随一点点过度?)
可能的答案可能是这种情况不是那么特别:它是
类似于ANSI-C引用中的一些情况,例如\\\
。但是,这仍然是
nn
转义单个字符(八位字符的值为八进制
值nnn),而不是字符序列。解决方案只是为了完成,这是另一种方法来抑制别名&函数查找(通过清除单个命令的整个shell环境):
#cf. http://bashcurescancer.com/temporarily-clearing-environment-variables.html
env -i ls
In the first part of my question I will provide some background info as aservice to the community. The second part contains the actual question.
Part I
Assume I've created the following alias:
alias ls='ls -r'
I know how to temporarily unalias (i.e., override this alias) in the followingways, using:
1) the full pathname of the command:
/bin/ls
2) command substitution:
$(which ls)
3) the command builtin:
command ls
4) double quotation marks:
"ls"
5) single quotation marks:
'ls'
6) a backslash character:
\ls
Case 1 is obvious and case 2 is simply a variation. The command builtin in case 3 was designed to ignore shell functions, but apparently it also works for circumventing aliases. Finally, cases 4 and 5 are consistent with both the POSIX standard (2.3.1):
and the Bash Reference Manual (6.6):
Part II
Here's the question: why is case 6 (overriding the alias by saying
\ls
)considered quoting the word? In keeping with the style of this question, I am looking for references to the "official" documentation.The documentation says that a backslash only escapes the followingcharacter, as opposed to single and double quotation marks, which quote asequence of characters. POSIX standard (2.2.1):
Bash Reference Manual (3.1.2.1):
(BTW, isn't "the next character that follows" a bit of overkill?)
A possible answer might be that this situation isn't that special: it issimilar to a few cases in ANSI-C quoting, e.g.
\nnn
. However, that is stillescaping a single character (the eight-bit character whose value is the octalvalue nnn), not a sequence of characters.解决方案Just for completion, here's yet another way to suppress alias & function lookups (by clearing the entire shell environment for a single command):
# cf. http://bashcurescancer.com/temporarily-clearing-environment-variables.html env -i ls
这篇关于为什么反斜杠防止别名扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!