Bash – How to test for possible conflicts while using alias in bashrc

aliasbashbashrc

Is there a simple way to list all the command conflicts that have occurred in the system due to the bashrc update involving alias commands?

For example, someone writes alias ls=/path/to/user-generated/executable in bashrc. How does one find out that this is masking an actual command (ls). One way seems to be to run all the aliases before and after sourcing bashrc and diff the output. Are there any better ways?

I'm running Ubuntu 12.04.

bash –version

GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)

Best Answer

To find out what commands are masked by aliases, do something like this:

alias | sed 's/^[^ ]* *\|=.*$//g' | while read a; do
  printf "%20.20s : %s\n" $a "$(type -ta $a | tr '\n' ' ')"
done | awk -F: '$2 ~ /file/'

Explanation

alias alone lists defined aliases and sed extracts their name. The while loop runs type -ta on each of them and awk prints the lines that both contain alias and file.