<?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 &#187; bash</title>
	<atom:link href="http://www.ghacks.net/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghacks.net</link>
	<description>A technology blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description>
	<lastBuildDate>Tue, 24 Nov 2009 16:29:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Get to know Linux: Bash scripting basics</title>
		<link>http://www.ghacks.net/2009/05/20/get-to-know-linux-bash-scripting-basics/</link>
		<comments>http://www.ghacks.net/2009/05/20/get-to-know-linux-bash-scripting-basics/#comments</comments>
		<pubDate>Wed, 20 May 2009 18:23:46 +0000</pubDate>
		<dc:creator>Jack Wallen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=12956</guid>
		<description><![CDATA[After using Linux for a while you will eventually find yourself needing to create a bash script. And just what is a bash script? A bash script is a script that is run through the bash shell. Usually a bash script is a user-generated script that serves a specific purpose and combines numerous commands into [...]]]></description>
			<content:encoded><![CDATA[<p>After using Linux for a while you will eventually find yourself needing to create a bash script. And just what is a bash script? A bash script is a script that is run through the bash shell. Usually a bash script is a user-generated script that serves a specific purpose and combines numerous commands into one convenient script.</p>
<p>I am a big fan of bash scripting. I use them frequently to create backup scripts, scripts that are used via cron, and much more. But before I could write even a simple bash script, I had to understand the basics. And that&#8217;s what you will learn here &#8211; the very basics of bash scripting. This will be a foundation you can build upon so that your bash scripts can get more and more complex.</p>
<p><span id="more-12956"></span><strong>The structure</strong></p>
<p>A bash script consists of just a few pieces. First and foremost you have to actually create the file. This file will contain all of your scripting and will have to be made executable by the user. Once the file is complete and saved you will make this executable with the command:</p>
<p><em>chmod u+x FILENAME</em></p>
<p>Where FILENAME is the actual name of your file.</p>
<p>Now within the file you will have to at least have two minimal pieces:</p>
<ul>
<li>Shell declaration</li>
<li>Script</li>
</ul>
<p>The shell declaration is a statement that declares what shell you are to use. For nearly all of your Linux needs you will use the bash shell. To declare the bash shell being used your declaration will be:</p>
<p><em>#! /bin/bash</em></p>
<p>With that declaration all commands will be run through the bash shell.</p>
<p>The script is the contents of the shell script you will write. The script will most often consist of commands.</p>
<p><strong>Hello world</strong></p>
<p>Ah hello world! Who hasn&#8217;t or used this as an example. Let&#8217;s take a look at what an Hello World script wold look like. We&#8217;ll add a few variations to highlight some of the subtle differences.</p>
<p>The basic Hello World! script would look like:</p>
<p><code>#! /bin/bash<br />
echo "Hello World!"</code></p>
<p>Once you save it (we&#8217;ll call it &#8220;hello&#8221;) and make it executable you can run it by issuing the command:</p>
<p>~/hello</p>
<p>and you will see the output:</p>
<p><em>Hello World!</em></p>
<p>Now let&#8217;s use variable declaration in this script. Using variables will make your scripting much more versatile.</p>
<p><code>#! /bin/bash<br />
STRING1="Hello"<br />
STRING2="World!"<br />
echo $STRING1 $STRING2</code></p>
<p>Now let&#8217;s modify this to use a global variable. One useful global variable is USER. At the bash prompt enter <em>echo $USER </em>and bash will return the username that is currently logged in. So change your hello world script to look like:</p>
<p><code>#! /bin/bash<br />
STRING1="Hello"<br />
echo $STRING1 $USER</code></p>
<p>When you run this script you will see:</p>
<p><em>Hello USER</em></p>
<p>Where USER is the actual username logged in. You can test this by su&#8217;ing to a different user (such as root) and running the script. If you are root (make sure you su to root with the command <em>su &#8211; </em>or you won&#8217;t have root&#8217;s prompt, only root&#8217;s privileges) you will see:</p>
<p>Hello root</p>
<p><strong>Final thoughts</strong></p>
<p>And there you have the very fundamentals of bash scripting. Hopefully you can see how to build on the Hello World! example.</p>

	Tags: <a href="http://www.ghacks.net/tag/bash/" title="bash" rel="tag">bash</a>, <a href="http://www.ghacks.net/tag/bash-scripting/" title="bash scripting" rel="tag">bash scripting</a>, <a href="http://www.ghacks.net/tag/hello-world/" title="Hello World!" rel="tag">Hello World!</a>, <a href="http://www.ghacks.net/tag/linux/" title="Linux" rel="tag">Linux</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/01/06/save-your-skin-by-customizing-your-bash-prompt/" title="Save Your Skin by Customizing Your Bash Prompt (January 6, 2009)">Save Your Skin by Customizing Your Bash Prompt</a> (7)</li>
	<li><a href="http://www.ghacks.net/2009/02/06/get-to-know-linux-gnome-terminal/" title="Get To Know Linux: gnome-terminal (February 6, 2009)">Get To Know Linux: gnome-terminal</a> (5)</li>
	<li><a href="http://www.ghacks.net/2008/02/07/yoggie-pico-personal-mobile-security-computer/" title="Yoggie PICO Personal Mobile Security Computer (February 7, 2008)">Yoggie PICO Personal Mobile Security Computer</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/10/30/with-ubuntu-9-10-arrives-wubi-9-10/" title="With Ubuntu 9.10 Arrives Wubi 9.10 (October 30, 2009)">With Ubuntu 9.10 Arrives Wubi 9.10</a> (2)</li>
	<li><a href="http://www.ghacks.net/2006/12/07/widgets-for-linux-superkaramba/" title="Widgets for Linux: SuperKaramba (December 7, 2006)">Widgets for Linux: SuperKaramba</a> (6)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/05/20/get-to-know-linux-bash-scripting-basics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Get To Know Linux: gnome-terminal</title>
		<link>http://www.ghacks.net/2009/02/06/get-to-know-linux-gnome-terminal/</link>
		<comments>http://www.ghacks.net/2009/02/06/get-to-know-linux-gnome-terminal/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 03:56:20 +0000</pubDate>
		<dc:creator>Jack Wallen</dc:creator>
				<category><![CDATA[Desktop Manager]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[GNOME]]></category>
		<category><![CDATA[gnome-terminal]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=10353</guid>
		<description><![CDATA[If you use Linux for any amount of time, then most likely you have experienced the command line. And if you use the GNOME desktop environment then you know gnome-terminal. As far as terminals are concerned, gnome-terminal is one of the most versatile of the terminals. It features tabs, colored text, mouse event support, profiles, [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Linux for any amount of time, then most likely you have experienced the command line. And if you use the GNOME desktop environment then you know gnome-terminal. As far as terminals are concerned, gnome-terminal is one of the most versatile of the terminals. It features tabs, colored text, mouse event support, profiles, real transparency, compositing, and more. And of course you get glorious Linux commands!</p>
<p>The gnome-terminal comes pre-installed with any GNOME desktop installation, so if you&#8217;re running GNOME you won&#8217;t have to do any further installation. You might, however, want to undertake some configuration changes. We&#8217;ll examine some of those options here.</p>
<p><span id="more-10353"></span></p>
<div id="attachment_10355" class="wp-caption alignleft" style="width: 310px"><a href="http://www.ghacks.net/wp-content/uploads/2009/02/gnome_terminal_main.png"><img class="size-medium wp-image-10355" src="http://www.ghacks.net/wp-content/uploads/2009/02/gnome_terminal_main-500x356.png" alt="Default gnome-terminal Window" width="300" height="214" /></a><p class="wp-caption-text">Default gnome-terminal Window</p></div>
<p>When you start up the gnome-terminal you will be greeted by the default profile with a single tab open.</p>
<p>The default features you will notice immediately are the menu bar and the scroll bar. Outside of the bash prompt, the menu bar will be where you take care of most of your gnome-terminal business. Let&#8217;s examine what you will find in each menu entry:</p>
<p><strong>File:</strong> In this menu entry you can open/close a new tab, open/close a new terminal, and/or create a new profile.</p>
<p><strong>Edit:</strong> In this menu entry you can copy/paste, edit your profiles, and/or configure keyboard shortcuts.</p>
<p><strong>View: </strong>In this menu entry you can configure gnome-terminal to show/hide the menubar, and/or the scrollbar or you can zoom in or out.</p>
<p><strong>Terminal:</strong> In this menu entry you can change your profile, change your window title, set character encoding, reset your terminal, and/or reset and clear your terminal.</p>
<p><strong>Tabs:</strong> In this menu entry you can cycle through your open tabs and/or detach a tab (so it is its own window).</p>
<p><strong>Help:</strong> In this menu entry you can open up the GNOME Help system to learn about gnome-terminal and you can open the &#8220;about gnome-terminal&#8221; window.</p>
<p>That&#8217;s it for the tabs.</p>
<p>As I mentioned, the gnome-terminal is fairly configurable. You can make this terminal as minimal as you like. You can remove the scrollbar and the menubar if you like. To do this click on the View menu and de-select both the scrollbar and the menubar. What that leaves you with is nothing more than a terminal prompt in a window. Or does it? If you right click anywhere in the gnome-terminal window a menu will appear. From that menu you can select to, once again, show the menubar. Once the menubar is back you can then select to show the scrollbar.</p>
<p><strong>Profiles</strong></p>
<p>One of the nicest aspects of the gnome-terminal is that you can create profiles. Each profile can reflect, say, a different job. Say you want to have a root user profile. This can make for an easy way to instantly know you are using the root user (so you don&#8217;t commit any command-line fouls that could damage your system). To create a new profile click on File and then select New Profile.  What you will see is a small window asking you to name the new profile and base the new profile on a pre-existing profile.</p>
<p>Once the new profile is named the main Profile editor window will appear where you can really tweak your profile. There are six tabs within the Profile editor:</p>
<p><strong>General: </strong>Configure the general options such as name, font, show menubar, terminal bell.</p>
<p><strong>Title and Command: </strong>Give this profile an initial title and run custom commands (such as automatically listing directory contents when a profile is opened.)</p>
<p><strong>Colors: </strong>Foreground and background colors.</p>
<p><strong>Background: </strong>Configure a background image or window transparency.</p>
<p><strong>Scrolling: </strong>Place the scroll bar and define how far back it will scroll.</p>
<p><strong>Compatibility: </strong>Configure the backspace and delete keys.</p>
<p><strong>Final thoughts</strong></p>
<p>I have used many terminals in my day, but the gnome-terminal is one of the finest. Not only is it very compatible, it is useful and user-friendly. If you use the GNOME desktop (or an alternative desktop), make sure you get to know gnome-terminal for all your command line goodness.</p>

	Tags: <a href="http://www.ghacks.net/tag/bash/" title="bash" rel="tag">bash</a>, <a href="http://www.ghacks.net/tag/command-line/" title="command-line" rel="tag">command-line</a>, <a href="http://www.ghacks.net/tag/gnome/" title="GNOME" rel="tag">GNOME</a>, <a href="http://www.ghacks.net/tag/gnome-terminal/" title="gnome-terminal" rel="tag">gnome-terminal</a>, <a href="http://www.ghacks.net/tag/linux/" title="Linux" rel="tag">Linux</a>, <a href="http://www.ghacks.net/tag/prompt/" title="prompt" rel="tag">prompt</a>, <a href="http://www.ghacks.net/tag/terminal/" title="terminal" rel="tag">terminal</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/01/06/save-your-skin-by-customizing-your-bash-prompt/" title="Save Your Skin by Customizing Your Bash Prompt (January 6, 2009)">Save Your Skin by Customizing Your Bash Prompt</a> (7)</li>
	<li><a href="http://www.ghacks.net/2009/04/03/simple-gnome-note-taking-with-tomboy/" title="Simple GNOME Note Taking with Tomboy (April 3, 2009)">Simple GNOME Note Taking with Tomboy</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/13/searching-for-files-in-linux-via-command-line/" title="Searching for Files in Linux via Command Line (February 13, 2009)">Searching for Files in Linux via Command Line</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/02/15/quick-archiving-in-gnome/" title="Quick Archiving in GNOME (February 15, 2009)">Quick Archiving in GNOME</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/12/manage-network-devices-in-fedora/" title="Manage Network Devices in Fedora (March 12, 2009)">Manage Network Devices in Fedora</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/02/06/get-to-know-linux-gnome-terminal/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<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>

	Tags: <a href="http://www.ghacks.net/tag/bashrc/" title=".bashrc" rel="tag">.bashrc</a>, <a href="http://www.ghacks.net/tag/bash/" title="bash" rel="tag">bash</a>, <a href="http://www.ghacks.net/tag/bash-customization/" title="bash customization" rel="tag">bash customization</a>, <a href="http://www.ghacks.net/tag/linux/" title="Linux" rel="tag">Linux</a>, <a href="http://www.ghacks.net/tag/terminal/" title="terminal" rel="tag">terminal</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/06/get-to-know-linux-gnome-terminal/" title="Get To Know Linux: gnome-terminal (February 6, 2009)">Get To Know Linux: gnome-terminal</a> (5)</li>
	<li><a href="http://www.ghacks.net/2009/05/20/get-to-know-linux-bash-scripting-basics/" title="Get to know Linux: Bash scripting basics (May 20, 2009)">Get to know Linux: Bash scripting basics</a> (3)</li>
	<li><a href="http://www.ghacks.net/2008/02/07/yoggie-pico-personal-mobile-security-computer/" title="Yoggie PICO Personal Mobile Security Computer (February 7, 2008)">Yoggie PICO Personal Mobile Security Computer</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/10/30/with-ubuntu-9-10-arrives-wubi-9-10/" title="With Ubuntu 9.10 Arrives Wubi 9.10 (October 30, 2009)">With Ubuntu 9.10 Arrives Wubi 9.10</a> (2)</li>
	<li><a href="http://www.ghacks.net/2006/12/07/widgets-for-linux-superkaramba/" title="Widgets for Linux: SuperKaramba (December 7, 2006)">Widgets for Linux: SuperKaramba</a> (6)</li>
</ul>

]]></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>
