Search code examples
bashprompt

remove hyphen in bash prompt


My bash PS1 prompt is configured as:

export PS1="\e[1;38;5;120m\\n\s \V\\$ \e[0m"

It looks like

-bash 5.0.7$

Having the hyphen, -, in front of bash is quite annoying. Does anyone know how I can get rid of it?


Solution

  • The - appears because the login program runs your default shell with a prefixed - to indicate that a login shell should be used (equivalent to bash -l).

    \s is essentially just a synonym for basename "$0". If you can't easily change how your shell is run in the first place, you can modify your prompt to strip the - from $0 instead.

    PS1="\e[1;38;5;120m\\n${0#-} \V\\$ \e[0m"
    

    (Unless you specify otherwise, I'll assume no other processing of $0 is needed.)