How to tell bash not to expand aliases

I know there is a simple syntax for telling bash not to expand aliases. However, Google is not turning it up and I'm too lazy to read through man bash. Also, the answer should be on this website.


Put a backslash before the first character.

$ alias ls="echo foo"
$ ls
foo
$ \ls
bin
Desktop
Documents
  ...

You can use command shell builtin command. It will execute only commands found in the PATH or shell builtins. It won't execute aliases or shell functions.

Example:

alias ls='ls -l'
$ ls
drwxr-xr-x 3 user user 4096 2010-10-11 13:17 dir1
drwxr-xr-x 3 user user 4096 2010-10-15 15:37 dir2
$ function ls() {
> echo hello
> }
$ ls
hello
$ command ls
dir1  dir2

Type shopt -u expand_aliases into the bash shell (the -u switch is for unset). I recommend reading the man page for shopt.


As @bossNova has already suggested, to prevent alias expansion:

shopt -u expand_aliases

And for those who are curious, to set alias expansion:

shopt -s expand_aliases