Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Cool, thanks. I can't say I understand 100% of why exactly that works, but it does =] Commented Oct 16, 2010 at 0:26
  • the $'\033[38;5;2m' and $'\033[0m\n' parts are ANSI escape codes. The first one colors the contents of $prompt_history and the second resets the color to your terminals default. Commented Oct 16, 2010 at 0:50
  • I guess I should have clarified. What exactly is the reason for having to store prompt_history twice? Why does it need first the $() and then the {:7}? I think it has to do with executing the command every time instead of caching, but what are the rules on that? Is that why it's written how it is? Commented Oct 16, 2010 at 8:45
  • @Falmarri: history 1 prints a number before the command. As far as I know you can't directly perform string manipulation like ${:7} on the result of a command substitution in bash, hence the temporary variable. See my revised answer. Commented Oct 16, 2010 at 9:49
  • Sorry one more question. I'm not an expert in bash (yet), can you quickly explain the quotes in your echo? For example why is the first $ outside the quotes, and why is the ascii control character in single quotes? Commented Oct 16, 2010 at 19:28