I recently started using linux and thought it would be useful to be able to see the working directory (not just the basename) so changed the ~/.bashrc file to this:

# ~/.bashrc

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
LGREEN="\[$(tput setaf 10)\]"
DGREEN="\[$(tput setaf 28)\]"
GREEN="\[$(tput setaf 2)\]"
RESET="\[$(tput setaf 255)\]"
TEAL="\[$(tput setaf 123)\]"
PS1="${RESET}/${LGREEN}\u@${GREEN}\t${DGREEN} \w ${RESET}\n\\ \[\[\033[5m\]${TEAL}>>\[\033[0m\]\]" 

I've tried everything I could think of: wrapping the escape characters in \[\], wrapping the color variables again in \[\], but nothing would work, the same thing happens: if the command I'm typing is too long to fit on a single line, instead of being wrapped properly and going on the next line, it overlaps with itself and looks broken.

  • Nitpicking, unrelated to your question: it's pretty unfortunate to name tput setaf 255 as reset. This is light gray. Reset is \033[0m, or, to be more portable and consistent with the colors, tput sgr0.
    – egmont
    Oct 8, 2018 at 7:53

1 Answer 1


I think the newline should work in there, as the \n escape is explicitly listed as one of the prompt escapes. It should be easy for the shell to interpret, too, it just needs to reset the prompt length to zero when jumping to the next line.

As far as I tested, it seemed that the doubled \[\[ and \]\] at the end caused problems.

Here, you have one set of \[ \] around this whole final part, and then two sets of the same inside that.

  ^^^^^^^^^^^         ^^^^^^^^^^^

You should probably remove the outer ones:


The color codes are fine since you're using double quotes when setting PS1, so the color variables get expanded at assignment, and the \[ \] escapes within them work.

If the two-line prompt really doesn't work, you could always print the first line through PROMPT_COMMAND.

Something like PROMPT_COMMAND='printf "${RESET}/${LGREEN}$USER@${GREEN}$(date +%T)${DGREEN} $PWD ${RESET}\n"' should work, though in that case, you need to have the color variables without the \[ \].

  • Thank you very much, removing the outer \[ \] solved the problem. Oct 8, 2018 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .