've just started using Ubuntu. I wish to use a few homemade aliases and environment variables, so I did the following :
Put those homemade aliases in a
initializer_file.sh
file, which I located at my personal subdirectory$HOME/Teuliou/Bash_scripts/initializer_file.sh
Add the following lines at the end of the
.profile
file :
# include homemade initializer file if it exists
if [ -f "$HOME/Teuliou/Bash_scripts/initializer_file.sh" ]; then
. "$HOME/Teuliou/Bash_scripts/initializer_file.sh"
fi
This does nothing however. When I open a new terminal after having saved the .profile
file, my aliases are still unknown commands.
On the other hand, I know that the code inside initializer_file.sh
is correct because if I copy-paste it into a terminal the aliases
work.
What am I doing wrong ?
This is normal. It did not work because
.profile
is only read once for a login-shell, i.e., when you log in. To make it work (provided your script is correct), log out, then back in. However, defining aliases through.profile
may not be the best way..bashrc
, is interpreted each time you open an interactive shell, i.e., when you open a terminal. It therefore makes more sense to define them through.bashrc
..bashrc
in Ubuntu is already configured to source a file.bash_aliases
if it exists. So it is most convenient to just put your custom alias definitions in.bash_aliases
.