bodacydo
bodacydo

Reputation: 79319

How do I call a function in bash if there is an alias by the same name?

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?

Upvotes: 5

Views: 1245

Answers (2)

ajp15243
ajp15243

Reputation: 7952

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.

Upvotes: 0

anubhava
anubhava

Reputation: 785098

when I execute aaa the alias runs.

You can run it as:

\aaa

This will call function.

Upvotes: 8

Related Questions