0
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

I tried experimenting with this line a lot and was able to get a few characters, but I still don't get the complete meaning of the line. Can anyone please provide a detailed explanation of the line?

I got what I could from this resource

1 Answers1

1
  • ${debian_chroot:+($debian_chroot)} -- checks if the variable debian_chroot is set, and expands to its value in parenthesis if it is. Debian's bashrc sets the variable earlier, I never use it so, I don't remember how its set. ${var:+word} is a standard parameter expansion.

  • \[ .. \] -- marker for non-printing characters, namely the color codes here. Bash needs these to calculate the length of the prompt so that the UI works properly

  • \033[01;32m -- (that's ESC, backslash, etc.) terminal control code to set the output color (check any source on that for the meaning of the numbers)

  • \u@\h -- username, literal @, hostname

  • \w -- current working directory

  • \$ -- a dollar sign, unless you're root, in which case a hash sign #

  • Note that there's a trailing space before the ending quote. Without it, the cursor would right against the dollar sign, which looks ugly.

See Bash's manual for a reference on the backslash-codes it interprets in prompts.

ilkkachu
  • 138,973