5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PS1変数について小ネタ

5
Posted at

はじめに

この方の記事を読んで、シェルについて投稿しようと思いました。

プロンプトのカスタマイズはどうやってますか?

以下のように、一般ユーザなら「$」、ルートなら「#」を明示的に書く人が多いのではないでしょうか。

~/.bash_profile
 :
export PS1='$ '
 :

このやり方の欠点は、各ユーザの環境設定ファイルを編集する必要があります。

そこで以下のように実行してはいかがでしょうか。

/etc/profile
 :
export PS1='\$ '
 :

/etc/profileの1ファイルに記述をするだけで、ルートユーザなら「#」、一般ユーザなら「$」のプロンプトに自動的に変わるので、各ユーザの環境設定ファイルを編集しなくて済みます。

'$'の前には、ホスト名(\h)やユーザ名(\u)など設定することもできますよ。
他にもいっぱいできるけど、現実的なものはホスト名、ユーザ名くらいかと

まとめ

/etc/profileにPS1='$ 'を書こう!

5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?