My Bash aliases don't work

被刻印的时光 ゝ 提交于 2019-12-03 13:17:11
Sean Bright

Add this to the end of your .bashrc:

if [ -f $HOME/.bash_aliases ]
then
  . $HOME/.bash_aliases
fi

p.s.

When you may also need to load this first [ref][1]

shopt -s expand_aliases

I had a similar problem recently. The solution appeared to be closing ALL open shells (root and user; I didn't notice that I was running a minimized root shell at the time while editing my user .bashrc and .bash_aliases files). The .bash_aliases file then seemed to get read.

Bash doesn't look for a file called .bash_aliases; you have to source it explicitly.

Looking around a bit, it appears ~/.bash_aliases is sourced from the default .bashrc on Ubuntu boxes; I don't have access to one to confirm. However, it is not a standard bash configuration file.

prodigerati

I recently installed RVM and changed my terminal profile to "run command as login shell". This disabled .bashrc from loading.

Fix: edit -> profile preferences -> Title and Command -> Run command as a login shell (uncheck)

Find this post for more information, fixed it for me.

https://askubuntu.com/questions/161249/bashrc-not-executed-when-opening-new-terminal

By default

if [ -f ~/.bash_aliases ]; then
.  ~/.bash_aliases
fi

These are available in your .bashrc file in ubuntu 18,19 Actually the problem is sourcing the files, therefore source both files by runing the commands below. I faced the same issues and that is how i solved it.

source ~/.bashrc
source ~/.bash_aliases

You need to include the file. Example code to do so from a default .bashrc file is below:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Sometimes forgetting to source the bashrc also creates this problem. So after adding your aliases don't forget to source it.

source ~/.bashrc
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!