Hack 42. PS1 変数内に bash シェル関数を使用する
以下で示すように PS1 で bash シェル関数を実行することもできます。
ramesh@dev-db ~> function httpdcount { > ps aux | grep httpd | grep -v grep | wc -l > } ramesh@dev-db ~> export PS1="\u@\h [`httpdcount`]> " ramesh@dev-db [12]> [Note: これは実行中の httpd プロセスの総数を表示します]
この変更を永続化するために ~/.bash_profile あるいは ~/.bashrc に次の行を追加できます:
$ vi .bash_profile function httpdcount { ps aux | grep httpd | grep -v grep | wc -l } export PS1='\u@\h [`httpdcount`]> '