I want to create my own alias to make some command more simpler.I add
alias ll='ls -l' in ~/.bashrc,like this:
ANDROID_NAME=/Users/smy/Library/Android/sdk
PYTHONPATH=/Library/Python/2.7/site-packages:$PYTHONPATH
PATH=$ANDROID_NAME/platform-tools:$PYTHONPATH:$PATH
export ANDROID_HOME
export PYTHONPATH
export PATH
#alias
alias ll='ls -l'
when I first add this alias to this file,I execute source command,like this:
source ~/.bashrc
then in this command window,it can works,but when I create a new command window,it can't recognize the ll alias,that is when I execute ll,such error exists:
-bash: ll: command not found
when I type source ~/.bashrc,it will work.
So my question is:
why the alias can't be recognized whenever I type it,why I must execute source command to make it work when new command window opened,and how I can resolve this. I'm working on mac,Anyone can teach me about this,thanks!
You need to use ~/.bash_profile or ~/.profile for login shells instead of ~/.bashrc. From the documentation:
When Bash is invoked as an interactive login shell, or as a non-interactive shell with the
--loginoption, it first reads and executes commands from the file/etc/profile, if that file exists. After reading that file, it looks for~/.bash_profile,~/.bash_login, and~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
and:
When an interactive shell that is not a login shell is started, Bash reads and executes commands from
~/.bashrc, if that file exists.
When opening a new terminal window/tab, the shell should be opened as a login shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With