PS1 シェル変数 ~/.bashrc に設定する必要があります bash の場合 これは、対話型シェル セッションで読み込まれる初期化ファイルです。
この変数はシェル変数であることに注意してください 、環境変数ではありません(子プロセスにその値を継承させることは意味がありません。それを使用するのは現在のシェルだけです)。したがって、export でエクスポートする必要はありません。 .
関連:
- .bashrc の目的とその仕組みは?
bash を開始する必要はありません。 シェルの起動ファイルのいずれかから。 ~/.profile から特定のシェルを開始する (またはログイン シェルに関連する対応するファイル) は、実行しているシステムでログイン シェルの変更が許可されていない場合に保証される可能性があります。 しないように注意してください ただし、それが既にファイルを実行しているシェルである場合は、別のシェルを開始してください。そうしないと、一種の無限ループに陥る可能性があります。
exec ~/.bash_profile に追加するコード 決して必要とされるべきではありません。 ~/.bashrc を取得する方法だと思います 解析する (対話型シェルを開始し、対話型 bash シェルは ~/.bashrc を読み取りました )。これを行うより良い方法は、ファイルの 1 つを別のソースにすることです。たとえば、~/.bash_profile でこれを使用します。 :
if [[ -f $HOME/.bashrc ]]; then
source "$HOME/.bashrc"
fi
次に、PS1 を設定します ~/.bashrc で (HOME に触れる必要はないはずです または TERM ).
コマンドが行うもう 1 つのことは、env -i を使用して他のすべての環境変数を消去することです。 . 非常に具体的な理由がない限り これを行うには、通常のシェル起動ファイルからそれを行うべきではありません。
bash のマンページから引用するには:
When bash is invoked as an interactive login shell, or as a non-interactive
shell with the --login option, 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. The
--noprofile option may be used when the shell is started to inhibit this
behavior.
When a login shell exits, bash reads and executes commands from the file
~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash reads
and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files
exist. This may be inhibited by using the --norc option. The --rcfile file
option will force bash to read and execute commands from file instead of
/etc/bash.bashrc and ~/.bashrc.
そのため、シェルの起動方法に大きく依存します。
PS1が必要な場合 すべてのログインでアクティブ シェル (例:su - <user>経由) またはssh経由でリモートでログインする場合 )、プロフィールに入れます .PS1を手に入れたい場合 すべての非ログインでアクティブ シェル (たとえば、デスクトップ環境で別のターミナルを開くだけ)、bashrc に入れます .- 両方のケースでアクティブにしたい場合は、両方のファイルに入れる必要があります。または (少なくともシステム全体の /etc/profileエム> および /etc/bash.bashrc )、.bashrc をソースします .profile で .
PS1 .bashrc である必要があります . .profile で設定することもできます .
Debian はそこから .bashrc をソースします:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi