I have alias ready on .bash_aliases
.
Problem I'm having right now is that I need to run source ~/.<filename>
first before I can execute the alias command.
My question would be how do I run the source ~/.<filename>
when user opens terminal.
I have alias ready on .bash_aliases
.
Problem I'm having right now is that I need to run source ~/.<filename>
first before I can execute the alias command.
My question would be how do I run the source ~/.<filename>
when user opens terminal.
You might put source ~/.bash_aliases
in your ~/.bashrc
file, or actually define aliases there.
Just mention that .bash_alieases script into .profile in your home directory. something like that
cat >> ~/.profile
/bin/sh ~/.bash_alieases
cltd+d
Next time whenever you open a terminal it will execute that .bash_alieases file automatically.
~/.bash_alieases
file in ~/.profile
file. This file is not read by bash(1), if ~/.bash_profile
or ~/.bash_login
exists. Normally, ~/.bash_alieases
file is already sourced in ~/.bashrc
file.
– Radu Rădeanu
Aug 20 '13 at 11:36
You don't need to source ~/.bash_alieases
file in ~/.bashrc
file. If you look with attention in ~/.bashrc
file you will find somewhere after line 100 the following lines:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
This mean: if the file ~/.bash_aliases
exists and is a regular file, then execute the file. source ~/.bash_aliases
and . ~/.bash_aliases
are synonymous in bash (see What is the difference between "source" and "." in bash?).
Only if by some mistake you don't have the above lines you should add them again in your ~/.bashrc
file.
Finally, if you are interested to run any other file on terminal start up, a good way is to source that file inside ~/.bashrc
file as follow:
source ~/<filename>
or, simple:
. ~/<filename>
.bash_aliases
then it might be that the user messed up with sourcing the file. It was my assumption too that if the line is present they may also notice that aliases file is already sourced and ask why it doesn't work, but messed-up syntax or other errors in.bashrc
is IMO not relevant to this specific question, at least in its present form. – moon.musick Aug 20 '13 at 11:44