Fun With Bash

---

I’ve been playing around with the Bash environment variable $PS1 lately. If you don’t know what that means, Bash has four built-in variables for the prompt, $PS[1-4] (more detail). $PS1 is the variable that defines what you see each line.

The default setting for $PS1 is “\s-\v\$ “. What this means is that it will show the name and version of your bash prompt in the format:

bash-3.1$

Granted, I’ve never used a distro that hasn’t changed this default prompt. Usually, you have a default prompt something like “\u@\h\$ ” or “\u@\h:\w\$ “, which will yield results like:

possum@haruko$

or:

possum@haruko:~/projects/perl$

respectively. If you want to make your friends jealous, you can modify this pretty easily, using prompt expansion codes. These allow you to include things such as date, time, and more fun things.

Additionally, any relatively recent terminal supports colors! You can use escape codes to set background and foreground colors to get a very unique shell.

Finally, you can execute programs even from within your prompt, simply by surrounding them with backticks (`). This way, you can have, for instance, your system uptime always present in your prompt.

Alright, if your ready, here’s my monster of a prompt. To get the same effect, just add this line to your ~/.bash_profile (all one line):

And a screenshot:

Screenshot

Web 2.0 Bookmarks:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Reddit
  • Slashdot
  • Technorati
  • YahooMyWeb

No Responses

Comments are closed.