防止alias解释
Bash有一个alias内部命令,可以为命令创建别名,别名可以覆盖原程序名。如alias ls='ls -h --show-control-chars --color=auto'。
这样,当输入ls时,就会有彩色显示、人类可阅读(查看大小时显示合适的单位而不是字节)和特殊字符显示。
有时候我们可能不想使用这种附加的功能,又不想unalias,有什么办法?
方法
使用绝对路径
使用/bin/ls这样的形式。由于alias只管行首的单词,这样就跳过了。
使用command
可以用command ls的形式使用,这样也可以跳过函数解析(如果你建立了一个ls()函数)
使用反斜杠(推荐)
这是Cygwin默认.bashrc中的一段注释:
# Aliases
# #######
# Some example alias instructions
# If these are enabled they will be used instead of any instructions
# they may mask. For example, alias rm='rm -i' will mask the rm
# application. To override the alias instruction use a \ before, ie
# \rm will call the real rm not the alias.
使用\ls,l\s,\foo,f\oo,fo\o,\f\o\o,也可以跳过alias解析。
在Bash一般情况下,反斜杠只有引用作用,没有转义作用,alias一开始就要被展开,但是文本不符合,最后,这些反斜杠会在引用去除时去掉,就执行原命令了。