Linuxdoc Linux Questions
Click here to ask our community of linux experts!
Custom Search

Chapter 11. Prompt Code Snippets

This section shows how to put various pieces of information into the Bash prompt. There are an infinite number of things that could be put in your prompt. Feel free to send me examples, I'll try to include what I think will be most widely used. If you have an alternate way to retrieve a piece of information here, and feel your method is more efficient, please contact me. It's easy to write bad code, I do it often, but it's great to write elegant code, and a pleasure to read it. I manage it every once in a while, and would love to have more of it to put in here.

To incorporate shell code in prompts, it has to be escaped. Usually, this will mean putting it inside \$(<command>) so that the output of command is substituted each time the prompt is generated.

Please keep in mind that I develop and test this code on a single user 900 MHz Athlon with 256 meg of RAM, so the delay generated by these code snippets doesn't usually mean much to me. To help with this, I recently assembled a 25 MHz 486 SX with 16 meg of RAM, and you will see the output of the "time" command for each snippet to indicate how much of a delay it causes on a slower machine.