LoginSignup
15
14

More than 5 years have passed since last update.

Macのターミナルでプロンプト変数を変更(ホスト名などの$のところの表示)

Posted at
host:~ name$ 

となっているのを

name:~$ 

と短くするやり方の紹介です。

まずはecho $PS1を実行します。

$ echo $PS1
\h:\W \u\$

と、表示されるかと思います。
\h:\W \u\$の意味は、

意味
\h ホスト名       
: ':'の表示
\W 現在のディレクトリ名
\u ユーザー名
\$ '$'の表示

ということです。

そこで、PS1を変更していきます。

$ PS1='\u:\W\$' 

これで変更完了です!

しかし、再起動をすると設定が消えてしいます……。
そこで、設定を~/.bashrcに保存していきます。

.bashrcPS1='\u:\W\$'を書いていきます。

.bashrcを読み込むには、

source ~/.bashrc

.bashrcが再起動毎に読み込まれない場合は、
~/.bash_profileに以下を追記します。

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

これで無事に設定完了です。

15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14