<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>gHacks Technology News &#124; Latest Tech News, Software And Tutorials &#187; bash customization</title> <atom:link href="http://www.ghacks.net/tag/bash-customization/feed/" rel="self" type="application/rss+xml" /><link>http://www.ghacks.net</link> <description>A technology news blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description> <lastBuildDate>Sat, 11 Feb 2012 21:54:04 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/> <item><title>Save Your Skin by Customizing Your Bash Prompt</title><link>http://www.ghacks.net/2009/01/06/save-your-skin-by-customizing-your-bash-prompt/</link> <comments>http://www.ghacks.net/2009/01/06/save-your-skin-by-customizing-your-bash-prompt/#comments</comments> <pubDate>Tue, 06 Jan 2009 20:21:28 +0000</pubDate> <dc:creator>Jack Wallen</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[Tutorials Advanced]]></category> <category><![CDATA[Tutorials Basic]]></category> <category><![CDATA[.bashrc]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[bash customization]]></category> <category><![CDATA[terminal]]></category> <guid
isPermaLink="false">http://www.ghacks.net/?p=9685</guid> <description><![CDATA[If you do much work at the Linux command line then you know the bash prompt can offer you a lot of information. But by default the prompt itself isn&#8217;t too useful.  What you might not know is that you can customize the bash prompt in many ways. From configuring colors to the information bash [...]]]></description> <content:encoded><![CDATA[<p>If you do much work at the Linux command line then you know the bash prompt can offer you a lot of information. But by default the prompt itself isn&#8217;t too useful.  What you might not know is that you can customize the bash prompt in many ways. From configuring colors to the information bash reports, there are so many variations on the bash prompt you could play for days.</p><p>But there is one configuration you can do that is more helpful than any other. Have you ever accidentally issued a standard user command as the root user only to find yourself really regretting that command a millisecond later? It&#8217;s a common new Linux user mistake, but one that can be prevented. You&#8217;ll learn how to help yourself out here.</p><p><span
id="more-9685"></span>Before we get into the actual configuration (and how you can help yourself), let&#8217;s take a look at some basics. From your command line issue the following command <em>echo $PS1</em>. What you should see is the string that comprises your current default bash prompt. When I issue this command I see <strong>[\u@\h \W]\$</strong> and my prompt looks like <strong>[jlwallen@localhost ~]$</strong>. Let me explain what the components of the string are.</p><p>[ - When used alone this is simply a printed character.</p><p>\u - This prints out the current username.</p><p>@ - When used alone this is simply a printed character.</p><p>\h - This prints out the hostname of the machine up to the first dot.</p><p>\W - This prints out the basename of the current working directory (with the users home directory represented by the "~" character.</p><p>] &#8211; When used alone this is simply a printed character.</p><p>\$ &#8211; If root user this prints a &#8220;#&#8221; character, otherwise it prints a &#8220;$&#8221; character.</p><p>So let&#8217;s say you want to be clever and have a prompt that looks like <strong>URHERE (~):</strong></p><p>To create this issue the command:</p><p><em>PS1=&#8221;URHERE (\W): &#8220;</em></p><p>What the above command does is temporarily set your bash prompt. This prompt will last until you close out your terminal window. When you open a new terminal your default prompt will return.</p><p>To make this permanent you will need to open up your <strong>.bashrc</strong> file and add the line you entered as a command. The default <strong>.bashrc</strong> file might look like:</p><p><em># .bashrc</em></p><p><em># User specific aliases and functions<br
/> ? () { echo &#8220;$*&#8221; | bc -l; }</em></p><p><em># Source global definitions<br
/> if [ -f /etc/bashrc ]; then<br
/> . /etc/bashrc<br
/> fi</em></p><p>If you want to make this permanent add the line <em>PS1=&#8221;URHERE </em>(\W): &#8220;<em> </em>right under the <em># .bashrc</em> line. Save that file and open up a new prompt. Voila!</p><p><strong>Adding Color</strong></p><p>Okay, let&#8217;s take it to 11. One trick I like to employ is configuring the root prompt to be a different color than the standard user prompt. This way, if I see a red prompt, I instantly know I am dealing with the root user. Here is the trick with adding color. First you have to use a special string to indicate the beginning of a color. That string is:</p><p><em>\e[</em></p><p>Now to end a color you use the special string:</p><p><em>\e[m</em></p><p>For the color red you would use the string:</p><p>1;31m</p><p>So if you want the string <em>URHERE</em> to show up in red and the directory to remain the default white you would enter into the root user&#8217;s .bashrc file:</p><p>PS1=&#8221;\e[1;31mURHERE\e[m (\W): &#8221;</p><p>Here are the various colors you can use.</p><ul><li>0;30 &#8211; Black</li><li>0;31 &#8211; Red</li><li>0;32 &#8211; Green</li><li>0;33 &#8211; Brown</li><li>0;34 &#8211; Blue</li><li>0;35 &#8211; Purple</li><li>0;36 &#8211; Cyan</li></ul><p>The 0 equals the dark variation of the color and a 1 equals the lighter variation of the color.</p><p><strong>Final Thoughts</strong></p><p>You can really get creative with the bash prompt. With the basics you have learned here you can make your prompt both unique and helpful. If you come up with something really incredible post it here for all to enjoy!</p> ]]></content:encoded> <wfw:commentRss>http://www.ghacks.net/2009/01/06/save-your-skin-by-customizing-your-bash-prompt/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> </channel> </rss>
