achille
achille

Reputation: 315

PS1 does not echo backslash

I want this Bash prompt:

/\ /\
root@debian$:

I do:

PS1="/\  /\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"

Or:

PS1="/\  /\\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"

But I have:

/\  /
root@debian$:

Upvotes: 0

Views: 115

Answers (1)

iBug
iBug

Reputation: 37227

PS1 itself does an extra layer of interpretation:

PS1="/\  /\\\\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"
          ^^^^ 4 backslashes

Or better yet:

PS1="/\\\\  /\\\\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"

Output I get:

/\  /\
ibug@ubuntu$:

Pro-tip: Use single quotes to save yourself quite some escapes:

PS1='/\\  /\\\n'"${debian_chroot:+($debian_chroot)}"'\u@\h\$:'
    ^          ^^                                  ^^        ^

Upvotes: 3

Related Questions