初めてログインしたときにBashエイリアスを取得できませんでした。

初めてログインしたときにBashエイリアスを取得できませんでした。

私はvirtualbox仮想マシンでDebian 8.5(Jessie)を実行しています。仮想マシンに初めてログインしたときに実行されないいくつかのbashエイリアスがあります。しかし、 bashシェルの内部で実行すると機能します。起動時に動作するようにシステムを設定するにはどうすればよいですか?

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.

.bashrc私はインクルードにその行を入れました.bash_aliases

yourstruly@mate:~$ tail ~/.bashrc

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

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

ベストアンサー1

Bashが相互作用を開始したときログイン見つかった次のファイルの最初のファイルを実行するシェル:~/.bash_profile~/.bash_login~/.profile

これとは対照的に、~/.bashrc対話型実行にのみ適用されます。ログインしていませんシェル。

解決策は、実際に使用している~/.bashrcソースからソースを取得することです。次の行を追加します。~/.bash_profile~/.bash_login~/.profile

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

特殊変数$-にはアクティブシェルオプションが含まれ、対話型シェルはアクティブiオプションリストに含まれています。したがって、このソースは~/.bashrc対話型シェル用であり、対話型シェルに固有のものです。

おすすめ記事