Wednesday, March 4, 2009

042 在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]>

[注意:这里显示了所有运行的httpd进程数]

你可以将下面的代码加入到~/.bash_profile 或者 ~/.bashrc文件中让改变永久生效:
$ vi .bash_profile 
function httpdcount {
ps aux | grep httpd | grep -v grep | wc -l
}
export PS1='\u@\h [`httpdcount`]> '

No comments:

Post a Comment