Reputation: 169
I want to create a alias of my cd command
. I have created the .bashrc file and append the command cd ......
to it. (Since the file was newly created, it just has this one line that I added).
After that, only after I typed . ~/.bashrc
, can the alias works. If I close the terminal and open it again, I need to retype . ~/.bashrc
.
It's really annoying to do this every time. Is there any way to solve this problem?
Thank you so much for help
Upvotes: 0
Views: 2224
Reputation: 161954
When you login to linux system, only ~/.profile
will be called:
$ cat ~/.profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
You need to source ~/.bashrc
inside ~/.profile
manaully.
Read this to learn more.
EDIT:
If you're using iTerm2
on mac
, it actually start a login shell by default when open tabs.
But you can change it: Preferences > General > Command
Upvotes: 3
Reputation: 3646
If using OS X, append the alias to ~/.bash_profile
.
You could also add alias to ~/.bashrc
, then add source ~/.bashrc
to ~/.bash_profile
.
Better yet, put all your aliases in ~/.aliases
, and source it in ~/.bash_profile
.
By default, OS X first sources /etc/bashrc
(which shouldn't be modified unless absolutely necessary), then sources the user's ~/.bash_profile
at the start of every interactive session.
Upvotes: 2