2

I'm running Debian 8.5 (Jessie) on a virtualbox vm. I have some bash aliases that I can't get to run when I initially login to my vm. However, when I run bash from inside the shell, then they work. How can I configure my system to get them to work on startup?

yourstruly@mate:~$ tail ~/.bash_aliases
alias quit='exit'
alias reboot='sudo shutdown -r now'
alias halt='sudo shutdown -h now'

yourstruly@mate:~$ halt
-bash: halt: command not found
yourstruly@mate:~$ bash
yourstruly@mate:~$ halt
Connection to localhost closed by remote host.
Connection to localhost closed.

I have put lines in .bashrc to include .bash_aliases.

yourstruly@mate:~$ tail ~/.bashrc

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

if [ -f ~/.bash_alias ]; then
  . ~/.bash_alias
fi
user394
  • 14,404
  • 21
  • 67
  • 93

1 Answers1

2

When bash starts an interactive login shell, it runs the first one found of the following files: ~/.bash_profile, ~/.bash_login, and ~/.profile.

By contrast, ~/.bashrc is only run for interactive non-login shells.

The solution is to source ~/.bashrc in whichever of ~/.bash_profile, ~/.bash_login, and ~/.profile you actually use. Add a line like this:

if [[ $- = *i* ]]; then . ~/.bashrc; fi

The special variable $- contains the active shell options, and interactive shells include i in the list of active options. So this sources ~/.bashrc for interactive shells and only for interactive shells.

John1024
  • 74,655