Refresh aliases and functions after defining new aliases and functions?

Sourcing the changed file will provide access to the newly written alias or function in the current terminal, for example:

source ~/.bashrc

An alternative syntax:

. ~/.bashrc

Note that if you have many instances of bash running in your terminal (you mentionned multiple tabs), you will have to run this in every instance.


Typing . ~/.bashrc at the command line will run .bashrc and so any functions defined in that file will be created.

.bashrc itself will then also call and run .bash_aliases (if it exists) if .bashrc has this code in it:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

whereas using . ~/.bash_aliases alone (at the command line for example) will just try and run .bash_aliases without involving .bashrc and will give an error if the file doesn't exist (hence the file check test when in .bashrc).


Sometimes you will want to turn an alias into a function, but when you source the bashrc file, a weird error may occur:

. ~/.bashrc
bash: /home/username/.bashrc: line 38: syntax error near unexpected token `('
bash: /home/username/.bashrc: line 38: `hello_world() {'

This may be happening because the alias name is clashing with the name of the newly defined function. As far as I know, to avoid this one needs to unalias everything, then source the bashrc file:

bash-4.3 $
unalias -a && . $HOME/.bashrc