My Bash aliases don't work

大兔子大兔子 提交于 2019-12-21 04:23:10

问题


I'm not sure why but my Bash aliases don't seem to work. Here is my .bashrc file

    # v 0.0.1 - 7/03/12

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

# expanding history to 10000 commands
export HISTSIZE=10000

# don't store repeated commands more than once
export HISCONTROL=ignoredups

# where to look for Java
export JAVA_HOME=/Library/Java/Home

# tomcat server configuration
export CATALINA_HOME=/usr/local/apache-tomcat-6.0.35

# default editor
export EDITOR=vim

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

Here is my .bash_aliases file

# v 0.0.1 - 7/03/12

# aliases for directory traversal
alias ..='cd ../'
alias ...='cd ../../'
alias ....='cd ../../../'

alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'

alias got='git '
alias get='git '

回答1:


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



回答2:


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.




回答3:


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.




回答4:


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



回答5:


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




回答6:


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

source ~/.bashrc



回答7:


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


来源:https://stackoverflow.com/questions/11548093/my-bash-aliases-dont-work

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