Bash – How many different ways can you create an “alias” in Bash

aliasbashshell

I only know of two ways: alias foo=bar and function foo() { bar }.

The reason I'm asking is that – all of a sudden in one of my bash sessions – I cannot run the ln command because bash is erroring out with -bash: /usr/local/.../ln: No such file or directory (where the /usr/local/.../ is one of the entries in my PATH environment variable).

It's not a PATH issue though, because If I run which ln it outputs the expected binary of /usr/bin/ln (which I can run fine if I specify the absolute path).

I also checked for ln in my alias and function declarations, and there is nothing:

$ declare -f | grep ln
$ alias | grep ln

The problem is just occurring in one bash session. If I start a new shell, it works fine again, but I want to know what caused this problem all of a sudden in this one particular session of bash.

Any ideas as to what could be causing this?

Best Answer

Be careful when using the which command. Better to use the type ... command.

$ type ln
ln is /bin/ln

You can also use the whereis command:

$ whereis ln
ln: /bin/ln /usr/share/man/man1p/ln.1p.gz /usr/share/man/man1/ln.1.gz
Related Question