4

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.

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
Unknown
  • 205

3 Answers3

5

You might put source ~/.bash_aliases in your ~/.bashrc file, or actually define aliases there.

Some background.

moon.musick
  • 1,958
0

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.

papseddy
  • 516
0

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>
Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407