2009年2月15日星期日

bash PS1

linux的世界何其大...我可能只講出一些皮毛=_=

今次談一談我使用bash時發覺如current directory 有太多層,

$cd directory1/directory2/directory3/directory4......directoryn
那麼command line 內的prompt string便顯示了所有的directoy,
directory1/directory2/directory3/directory4...directoryn$
結果可以打字的地方不足夠,經常會跳到下一行,非常不方便,請看下圖。












其實prompt string只顯示最後一個diretoryn 就足夠了。
這個簡單方法是一位高手教我的,在此先行謝過。
原來bash 裡有一個envirnoment variable 空制 prompt string, 那個就是
PS1,

只要在把PS1="\u@\h:\W\$" 
有的小楷 w 改為'W' 便可以了,












也可以在$home/.bashrc 修改,那麼以後就不用改了,prompt string還有很多玩法,
有興趣可以去找找。

6.9 Controlling the Prompt

The value of the variable PROMPT_COMMAND is examined just before Bash prints each primary prompt. If PROMPT_COMMAND is set and has a non-null value, then the value is executed just as if it had been typed on the command line.

http://www.gnu.org/software/bash/manual/bashref.html


English version:

The prompt string in bash is too long for me, if the current directoy is very deep in the file system.

$cd directory1/directory2/directory3/directory4......directoryn
directory1/directory2/directory3/directory4...directoryn$

In this case, a single line is not enough space of me to type the command.

To resolve this, there is an envirnoment varible PS1 in bash,
just modify it from 'w' to 'W' , then it is ok.
Save it in home directory $home/.bashrc, then it is effective every time when you login.

2 則留言:

  1. 完全唔明-_______________-"

    回覆刪除
  2. 係我表達得唔好...
    post兩幅圖上來..希望有d幫助。

    回覆刪除