Why do backslashes prevent alias expansion? Why do backslashes prevent alias expansion? shell shell

Why do backslashes prevent alias expansion?


Historically, and maintained by POSIX, quoting any part of the word causes the entire word to be considered quoted for the purposes of functions and alias expansion. It also applies to quoting the end token for a here document:

cat << \EOFthis $text is fully quotedEOF


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.htmlenv -i ls


\ls only quotes the first character rather than the whole word. It's equivalent to writing 'l's.

You can verify it like this:

$ touch \?l$ \??bash: ?l: command not found

If \?? quoted the whole word it would say ?? not found rather than ?l not found.

I.e. it has the same effect as:

$ '?'?bash: ?l: command not found

rather than:

$ '??'bash: ??: command not found