The part that you mention comes earlier in the .bashrc
, while what's mentioned in the duplicate comes a little bit later, in the PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
part. They work together, though !
So what does the code you mention say in terms of plain English ? Here it is for reference.
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
It starts with this part ${debian_chroot:-}
. Do we have that debian_chroot
variable set ? If yes, echo that variable, but if not - echo whatever comes after -
. And what comes after -
? Nothing ! Exactly that ! Why bother ? What if the variable is set ? Then we don't need to execute body of the if statement and just use debian_chroot
variable as is inside PS1 prompt later. Remember I said those two pieces of code work together ? OK, moving on.
Next step, if we evaluated the variable to be blank, we check for existance of readable /etc/debian_chroot
file. On Ubuntu 14.04 at least , there's no /etc/debian_chroot
file. So whenever you start bash it goes "Oh, so debian_chroot is not set and we don't have that file there . . .OK, leave only \u@\h:\w\$ inside the prompt ! "
Now what happens if we DO have that file ?
xieerqi:
$ sudo vi /etc/debian_chroot
[sudo] password for xieerqi:
xieerqi:
$ bash
(HELLOWORLD)xieerqi@eagle:~$ echo $debian_chroot
HELLOWORLD
(HELLOWORLD)xieerqi@eagle:~$
OK, trace the code again : do we have debian_chroot
set ? No. Do we have that /etc/debian_chroot
file ? Yes, so take its contents , and shove them into this users PS1
prompt. Looks like that's exactly what happened in my output, right ?