What is the difference between PS1 and PROMPT_COMMAND

后端 未结 6 1674
栀梦
栀梦 2020-12-07 07:58

While taking a look at this awesome thread I noticed that some examples use

PS1=\"Blah Blah Blah\"

and some use

PROMPT_CO         


        
6条回答
  •  再見小時候
    2020-12-07 08:56

    From man bash:

    PROMPT_COMMAND

    If set, the value is executed as a command prior to issuing each primary prompt.

    PS1

    The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is ''\s-\v\$ ''.

    If you simply want to set the prompt string, using PS1 alone is enough:

    PS1='user \u on host \h$ '
    

    If you want to do something else just before printing the prompt, use PROMPT_COMMAND. For example, if you want to sync cached writes to disk, you can write:

    PROMPT_COMMAND='sync'
    

提交回复
热议问题