LoginSignup
2
2

More than 5 years have passed since last update.

【Mac】プロンプトの変更

Last updated at Posted at 2016-09-11

コマンドラインの$の前に表示される文字の変更方法
$の前に出力される文字は設定ファイルのPS1で設定しています。
PS1の値を変更すれば$の前に出力される文字を変更できます。

bashプロンプト設定用の特殊文字列 (PS1に設定する値)

特殊文字列 意味
\w 作業ディレクトリを表示
\W ホームディレクトリを ~ で示した作業ディレクトリ
\! コマンド履歴
\H 完全なホスト名
\h 最初のピリオド記号のまでのホスト名
\@ 12時間 (a.m./p.m.) 表示形式の時刻
\A 24時間表示形式の時刻
\u ユーザ名
\$ ユーザ識別番号が0でスーパーユーザなら#記号。
それ以外は$記号

コマンド編

ホームディレクトリで以下のコマンドを実行。

~/
PS1="$ "

Screen Shot 2016-09-11 at 15.19.18.png
となる。

"作業ディレクトリ"、"コマンド履歴"、"$"を表示する場合

ホームディレクトリで以下のコマンドを実行。

~/
PS1="\w \! \$ "

Screen Shot 2016-09-11 at 15.35.04.png
となる。

手動編

bashシェルの環境設定ファイルを直接編集。設定ファイルは$HOME/.bash_profile

"$"マークだけ表示したい場合

export PS1="$ "を設定ファイルの末尾に追加。

Screen Shot 2016-09-11 at 15.19.18.png
となる。

--Note--
ターミナルが読み込む設定ファイルのうち、
システム全体で共有される設定ファイルは
"/etc/profile"と"/etc/bashrc"

2
2
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
2
2