Colour part of your prompt red to indicate an error

export PS1='[\[\e[36;1m\]\u@\[\e[32;1m\]\h \[\e[31;1m\]\w]# \[\e[0m\]'

By: bakhru
2011-04-16 00:58:51

1 Alternatives + Submit Alt

  • If the return code from the last command was greater than zero, colour part of your prompt red. The commands give a prompt like this: [user current_directory]$ After an error, the "[user" part is automatically coloured red. Tested using bash on xterm and terminal. Place in your .bashrc or .bash_profile.

    export PROMPT_COMMAND='if (($? > 0)); then echo -ne "\033[1;31m"; fi'; export PS1='[\[\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\]]\$ '
    quintic · 2010-08-25 21:19:30 0

What Others Think

Programers know why colour part is come. Colour part is come and you know the reason why code prompt colour indicate error. Those who are not aware with the colour they start reading on professional dissertation writer page which were indicate error which they show here.
Antonioomez · 94 weeks and 2 days ago
Ragdoll-Zeichnungen in Ablenkungen sind für Süchtige unerlässlich, und ich nutze zusätzlich die glückliche Pause, um solche Vergnügungen zu spielen, da ich eine fantastische Vitalität in Bezug auf diese Weiterleitungen habe. Ich spiele gerne 2020 casinos für diese Art von Einzahlungen. Diese Ablenkungen sind wichtig für Zweitstudien.
Jadyn11 · 71 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: