5

Take a look at this example:

[boda]$ alias aaa='echo aaa'
[boda]$ function aaa () { echo bbb }

[boda]$ function aaa () { echo bbb; }
[boda]$ aaa
aaa

As you can see I've both alias aaa and function aaa. However when I execute aaa the alias runs.

How do I run the function instead?

bodacydo
  • 75,521
  • 93
  • 229
  • 319
  • 5
    Don't define the alias, or use `unalias` to remove it. [anubhava's answer](http://stackoverflow.com/a/21738580/827263) is a good workaround, but the real problem is that you have a function and an alias with the same name, which inevitably leads to confusion. If at all possible, fix *that* problem. – Keith Thompson Feb 12 '14 at 20:11

2 Answers2

8

when I execute aaa the alias runs.

You can run it as:

\aaa

This will call function.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • +1, where can find documents talking about the usage of `\` here ? – BMW Feb 13 '14 at 00:46
  • 1
    **In Unix shells, if an alias exists for a command, it is possible to override the alias by surrounding the command with quotes or prefixing it with a backslash.** As per: http://en.wikipedia.org/wiki/Alias_(command) also [check this](http://unix.stackexchange.com/questions/39291/run-a-command-that-is-shadowed-by-an-alias) or [this Q&A](http://stackoverflow.com/a/16506263/548225) – anubhava Feb 13 '14 at 07:27
0

The man page for alias reveals that there is an unalias command.

unalias aaa

If you run this, even after both the alias and the function have been defined, calling aaa again should run the function. This does, however, destroy the alias. If that's undesirable, then anubhava's answer (or Keith Thompson's suggestion to not define them with the same name) is best.

ajp15243
  • 7,704
  • 1
  • 32
  • 38