<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Helpful Linux Tidbits</title>
	<atom:link href="http://linuxtidbits.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://linuxtidbits.wordpress.com</link>
	<description>Every Letter has it's place</description>
	<pubDate>Tue, 19 Aug 2008 18:35:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>Ansi2html</title>
		<link>http://linuxtidbits.wordpress.com/2008/08/19/ansi2html/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/08/19/ansi2html/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 18:35:19 +0000</pubDate>
		<dc:creator>Todd Partridge</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=436</guid>
		<description><![CDATA[At times it may be good idea to display the exact terminal output to viewers to easily convey what&#8217;s being done.  The cut and paste method works fine but ANSI coloring will be lost.  Lately I had some friends in the forums to help me figure this out.  
Ansi2html is a program [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>At times it may be good idea to display the exact terminal output to viewers to easily convey what&#8217;s being done.  The cut and paste method works fine but ANSI coloring will be lost.  Lately I had some friends in the forums to help me figure this out.  </p>
<p>Ansi2html is a program that can convert ANSI colored output and display it as a webpage.  Ansi2html is one of the programs that is part of kbtin, a MUD-client.  For Gentoo users, an ebuild thankfully rids the cruft and only ansi2html is built.  Thanks to timeBandit for pointing this out and thanks to tarpman for the <a href="http://forums.gentoo.org/viewtopic-p-5052845.html#5052845">ebuild</a>.  </p>
<p>Using ansi2html is easy, just enter:</p>
<pre>command -color | ansi2html &gt; command.html</pre>
<p>The color argument is required because color output is often repressed when output to a console or terminal (most popular commands have them).  For example:</p>
<pre>emerge -p --color=y frozen-bubble | ansi2html &gt; emerge-frozen-bubble.html</pre>
<p>Will give me this:</p>
<p><a href="http://ia311210.us.archive.org/1/items/OuputAnsi2html/emerge-epiphany.html">emerge-frozen-bubble.html link</a></p>
<p>I was thinking ansi2html might be good for displaying text inline on this Blog (as in preformatted colored text) but ansi2html builds a custom, built-in, css that make this all too unrealistic to build inline.</p>
<p>Have a good day.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/436/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/436/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/436/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=436&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/08/19/ansi2html/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/toddpartridge-128.jpg" medium="image">
			<media:title type="html">toddpartridge</media:title>
		</media:content>
	</item>
		<item>
		<title>Output Color on Bash Scripts - Advanced</title>
		<link>http://linuxtidbits.wordpress.com/2008/08/13/output-color-on-bash-scripts-advanced/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/08/13/output-color-on-bash-scripts-advanced/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 21:09:52 +0000</pubDate>
		<dc:creator>Todd Partridge</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=428</guid>
		<description><![CDATA[In my previous blog I talked about basic bash script colored output using the tput command.  The tput command is great for basic coloring (providing seven colors to choose from) but falls short if additional coloring is required.  Here we can use hardcoded ANSI coloring.  Warning - not all terminals support ANSI [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In my <a href="http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/">previous blog</a> I talked about basic bash script colored output using the tput command.  The tput command is great for basic coloring (providing seven colors to choose from) but falls short if additional coloring is required.  Here we can use hardcoded ANSI coloring.  Warning - not all terminals support ANSI (Most do though).</p>
<p>ANSI color coding is in this form:</p>
<pre><tt>/</tt>033[38;5;160m</pre>
<p>The ANSI sequence means: {ESC}[{attr};{fg};{bg}m</p>
<p>{ESC} or <tt>/</tt>033 represents the ANSI escape-sequence.  The escape is not the top left key but a ANSI designation a code is about to be input.  {attr} represents the outputs attributes (properties such as blinking and bold text), {fg} is the foreground color, {bg} is the background color, m means the sequence ends.</p>
<p>An example:</p>
<pre>echo -e "My favorite color is <tt>/</tt>033[38;5;148mYellow-Green<tt>/</tt>033[39m"</pre>
<p>The variable -e is required here because echo doesn&#8217;t normally interpret backslashes as escape-sequences.  Also 033[39m tells bash to end the coloring.</p>
<pre>echo -e "My favorite color is <tt>/</tt>033[38;5;148mYellow-Green<tt>/</tt>033[39m and <tt>/</tt>033[38;5;128mViolet<tt>/</tt>033[39m"</pre>
<p>Freexx has <a href="http://frexx.de/xterm-256-notes/">nice converter</a> that converts hexidecimal code to the corresponding ANSI foreground escape sequence.  It can be found halfway down the page called xterm256-conv2.tar.bz2.</p>
<p>Install and:</p>
<pre>echo d3d7cf | conv-rgb2xterm</pre>
<p>I also use a nice script called <a href="http://www.vim.org/scripts/script.php?script_id=1349">colortest</a> that listed xterms 256 colors in hexidecimal format.</p>
<pre>colortest -w</pre>
<p><strong>References:</strong></p>
<ul>
<li><a href="http://www.linuxjournal.com/article/8603">So You Like Color&#8211;The Mysterious ^[[ Characters</a></li>
<li><a href="http://tldp.org/LDP/abs/html/colorizing.html">&#8220;Colorizing&#8221; Scripts</a></li>
<li><a href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html">Tput Usage</a> (Thanks to arcanex for pointing me on how to use the tput command!)</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/428/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/428/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/428/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=428&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/08/13/output-color-on-bash-scripts-advanced/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/toddpartridge-128.jpg" medium="image">
			<media:title type="html">toddpartridge</media:title>
		</media:content>
	</item>
		<item>
		<title>Output color on bash scripts</title>
		<link>http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 22:53:37 +0000</pubDate>
		<dc:creator>Todd Partridge</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=424</guid>
		<description><![CDATA[Using Linux for awhile users find it&#8217;s fairly easy to learn basic bash scripting to perform multiple commands.  If you&#8217;d like to add a little bing to your scripts you can color command output in a fairly straight forward way by using the tput command.
Now, what I like to do is define the colors [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Using Linux for awhile users find it&#8217;s fairly easy to <a href="http://www.panix.com/~elflord/unix/bash-tute.html">learn basic bash scripting</a> to perform multiple commands.  If you&#8217;d like to add a little bing to your scripts you can color command output in a fairly straight forward way by using the tput command.</p>
<p>Now, what I like to do is define the colors the tput can produce at the beginning of the bash script:</p>
<pre>TXT_BLD=$(tput bold)
TXT_RED=$(tput setaf 1)
TXT_GREEN=$(tput setaf 2)
TXT_YLW=$(tput setaf 3)
TXT_BLUE=$(tput setaf 4)
TXT_PURPLE=$(tput setaf 5)
TXT_CYAN=$(tput setaf 6)
TXT_WHITE=$(tput setaf 7)
TXT_RESET=$(tput sgr0)</pre>
<p>A command bracket follow by the definition can now be used.  For example:</p>
<pre>echo "A great color is ${TXT_YLW}yellow${TXT_RESET}."</pre>
<p>Here&#8217;s my snapshot utility which provides coloroutput on how to use it.</p>
<pre>#!/bin/bash
# snapshot - take a screenshot of a selected part of the screen.

SCREENNAME=$@

TXT_BLD=$(tput bold)
TXT_RED=$(tput setaf 1)
TXT_GREEN=$(tput setaf 2)
TXT_YLW=$(tput setaf 3)
TXT_BLUE=$(tput setaf 4)
TXT_PURPLE=$(tput setaf 5)
TXT_CYAN=$(tput setaf 6)
TXT_WHITE=$(tput setaf 7)
TXT_RESET=$(tput sgr0)

# Utililization
if [[ -z $SCREENNAME ]]; then
    echo " ${TXT_BLD}${TXT_GREEN}*${TXT_RESET} ${TXT_YLW}snapshot ${TXT_RESET} to take high quality JPEG snapshot."
    echo " ${TXT_BLD}${TXT_GREEN}*${TXT_RESET} snapshot is saved to current folder, extension automatically appended."
    exit;
fi

# Take Snapshot (quality 95 is best quality and compression).
import -quality 95 "$SCREENNAME".jpg</pre>
<p>In another blog, I&#8217;ll write about using additional colors for bash scripting output.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/424/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/424/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/424/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=424&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/toddpartridge-128.jpg" medium="image">
			<media:title type="html">toddpartridge</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick Guide to Writing Scripts (Repub.)</title>
		<link>http://linuxtidbits.wordpress.com/2008/06/05/quick-guide-to-writing-scripts-repub/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/06/05/quick-guide-to-writing-scripts-repub/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 18:44:20 +0000</pubDate>
		<dc:creator>Todd Partridge</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=423</guid>
		<description><![CDATA[Note: This is a re-publication of elflords original Quick Guide to Writing Scripts minus a few type-o&#8217;s that I&#8217;ve re-published with his permission.  It is a really good tutorial for those new to bash scripting that like getting their hands dirty without all the fluff that goes with it.
A quick guide to writing scripts [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="background-color:#C3D1E6;color:#000000;font-weight:normal;padding:1px;"><strong>Note: </strong>This is a re-publication of elflords original <a href="http://www.panix.com/~elflord/unix/bash-tute.html">Quick Guide to Writing Scripts</a> minus a few type-o&#8217;s that I&#8217;ve re-published with his permission.  It is a really good tutorial for those new to bash scripting that like getting their hands dirty without all the fluff that goes with it.</span></p>
<p><H2>A quick guide to writing scripts using the bash shell</H2></p>
<p><H3>A simple shell script</H3></p>
<p>A shell script is little more than a list of commands that are run in sequence. Conventionally, a shell script should start with a line such as the following:</p>
<pre>#!/bin/bash</pre>
<p>This indicates that the script should be run in the bash shell regardless of which interactive shell the user has chosen. This is very important, since the syntax of different shells can vary greatly.<br />
<H4>A simple example</H4></p>
<p>Here&#8217;s a very simple example of a shell script, it runs a few simple commands.</p>
<p><PRE>#!/bin/bash
echo &#8220;hello, $USER. I wish to list some files of yours&#8221;
echo &#8220;listing files in the current directory, $PWD&#8221;
ls     # list files</pre> </p>
<p>First, notice the comment on line 4. In a bash script, anything following a pound sign # (besides the shell name on the first line) is treated as a comment (ie the shell ignores it). It is there for the benefit of people reading the script.</p>
<p>$USER and $PWD are <EM>variables</EM>. These are standard variables defined by the bash shell itself, they needn&#8217;t be defined in the script. Note that the variables are <EM>expanded</EM> when the variable name is inside double quotes. Expanded is a very appropriate word: the shell basically sees the string $USER and replaces it with the variable&#8217;s value then executes the command.</p>
<p>We continue the discussion on variables below &#8230; </p>
<p><H3>Variables</H3></p>
<p>Any programming language needs variables. You define a variable as follows: </p>
<p><code>X="hello"</code> </p>
<p>and refer to it as follows: </p>
<p><code>$X</code></p>
<p>More specifically, $X is used to denote the value of the variable X. Some things to take note of regarding semantics:<br />
<UL><br />
  <LI>Bash gets unhappy if you leave a space on either side of the = sign. For<br />
  example, the following gives an error message:<br />
  X = hello<br />
  <LI>While I have quotes in my example, they are not always necessary. Where you need quotes is when your variable names include spaces. For example:<br />
  X=hello world # error<BR>X=&#8221;hello world&#8221; # OK<br />
   </LI></UL></p>
<p>This is because the shell essentially sees the command line as a pile of commands and command arguments separated by spaces. <CODE>foo=bar</CODE>is considered a command. The problem with <CODE>foo = bar</CODE> is the shell sees the word <CODE>foo</CODE> separated by spaces and interprets it as a command. Likewise, the problem with the command <CODE>X=hello world</CODE> is that the shell interprets <CODE>X=hello</CODE> as a command, and the word &#8220;world&#8221; does not make any sense (since the assignment command doesn&#8217;t take arguments). </p>
<p><H4>Single Quotes versus double quotes</H4></p>
<p>Basically, variable names are expanded within double quotes, but not single quotes. If you do not need to refer to variables, single quotes are good to use as the results are more predictable. </p>
<p>An example:</p>
<p><PRE>#!/bin/bash
echo -n &#8216;$USER=&#8217;     # -n option stops echo from breaking the line
echo &#8220;$USER&#8221;
echo &#8220;\$USER=$USER&#8221;  # this does the same thing as the first two lines
</pre> </p>
<p>The output looks like this (assuming your username is elflord)<br />
<PRE>$USER=elflord</pre></p>
<p>The double quotes still have a work around. Double quotes are more flexible, but less predictable. Given the choice between single quotes and double quotes, use single quotes.</p>
<p><H4>Using Quotes to enclose your variables</H4><br />
<br />
Sometimes, it is a good idea to protect variable names in double quotes. This is usually the most important if your variables value either (a) contains spaces or (b) is the empty string. An example is as follows:<br />
<PRE>#!/bin/bash
X=&#8221;"
if [ -n $X ]; then 	# -n tests to see if the argument is non empty
	echo &#8220;the variable X is not the empty string&#8221;
fi</pre> </p>
<p>This script will give the following output: </p>
<p><code>the variable X is not the empty string</code> </p>
<p>Why?  Because the shell expands $X to the empty string. The expression [ -n ] returns true (since it is not provided with an argument). A better script would<br />
have been:<br />
<PRE>#!/bin/bash
X=&#8221;"
if [ -n "$X" ]; then 	# -n tests to see if the argument is non empty
	echo &#8220;the variable X is not the empty string&#8221;
fi</pre> </p>
<p>In this example, the expression expands to [ -n "" ] which returns false, since the string enclosed in inverted commas is clearly empty.</p>
<p><H4>Variable Expansion in action</H4></p>
<p>Just to convince you that the shell really does &#8220;expand&#8221; variables in the sense I mentioned before, here is an example:<br />
<PRE>#!/bin/bash
LS=&#8221;ls&#8221;
LS_FLAGS=&#8221;-al&#8221;

$LS $LS_FLAGS $HOME</pre> </p>
<p>This looks a little enigmatic. What happens with the last line is that it actually executes the command</p>
<p>ls -al /home/elflord </p>
<p>(assuming that /home/elflord is your home directory). That is, the shell simply replaces the variables with their values, and then executes the command. </p>
<p><H4>Using Braces to Protect Your Variables</H4></p>
<p>OK. Here&#8217;s a potential problem situation. Suppose you want to echo the value of the variable X, followed immediately by the letters &#8220;abc&#8221;. Question: how do you do this ? Let&#8217;s have a try:<br />
<PRE>#!/bin/bash
X=ABC
echo &#8220;$Xabc&#8221;
</pre> </p>
<p>This gives no output. What went wrong? The answer is that the shell thought that we were asking for the variable Xabc, which is uninitialised. The way to deal with this is to put braces around X to separate it from the other characters. The following gives the desired result:<br />
<PRE>#!/bin/bash
X=ABC
echo &#8220;${X}abc&#8221;
</pre> </p>
<p><H3>Conditionals, if/then/elif</H3><br />
Sometimes, it&#8217;s necessary to check for certain conditions. Does a string have 0 length?  Does the file &#8220;foo&#8221; exist, and is it a symbolic link, or a real file? First, we use the if command to run a test. The syntax is as follows:<br />
<PRE>if <EM>condition</EM>
then
	<EM>statement1</EM>
	<EM>statement2</EM>
	&#8230;&#8230;&#8230;.
fi
</pre> </p>
<p>Sometimes, you may wish to specify an alternate action when the condition fails. Here&#8217;s how it&#8217;s done.<br />
<PRE>if <EM>condition</EM>
then
	<EM>statement1</EM>
	<EM>statement2</EM>
	&#8230;&#8230;&#8230;.
else
	<EM>statement3</EM>
fi
</pre> </p>
<p>Alternatively, it is possible to test for another condition if the first &#8220;if&#8221; fails. Note that any number of elifs can be added.<br />
<PRE>if <EM>condition1</EM>
then
	<EM>statement1</EM>
	<EM>statement2</EM>
	&#8230;&#8230;&#8230;.
elif <EM>condition2</EM>
then
	<EM>statement3</EM>
	<EM>statement4</EM>
	&#8230;&#8230;..
elif <EM>condition3</EM>
then
	<EM>statement5</EM>
	<EM>statement6</EM>
	&#8230;&#8230;..
fi</pre> </p>
<p>The statements inside the block between <CODE>if/elif</CODE> and the next <CODE>elif</CODE> or <CODE>fi</CODE> are executed if the corresponding condition is true. Actually, any command can go in place of the conditions, and the block will be executed if and only if the command returns an exit status of 0 (in other words, if the command exits &#8220;successfully&#8221; ). However, in the course of this document, we will be only interested in using &#8220;test&#8221; or &#8220;[ ]&#8221; to evaluate conditions. </p>
<p><H4>The Test Command and Operators </H4><br />
The command used in conditionals nearly all the time is the test command. Test returns true or false (more accurately, exits with 0 or non zero status) depending respectively on whether the test is passed or failed. It works like this: </p>
<p>test <EM>operand1 operator<br />
operand2</EM> </p>
<p>for some tests, there need be only one operand (operand2) The test command is typically abbreviated in this form: </p>
<p>[ <EM>operand1 operator operand2 </EM>] To<br />
bring this discussion back down to earth, we give a few examples:<br />
<PRE>#!/bin/bash
X=3
Y=4
empty_string=&#8221;"
if [ $X -lt $Y ]	# is $X less than $Y ?
then
	echo &#8220;\$X=${X}, which is smaller than \$Y=${Y}&#8221;
fi

if [ -n "$empty_string" ]; then
	echo &#8220;empty string is non_empty&#8221;
fi

if [ -e "${HOME}/.fvwmrc" ]; then 			# test to see if ~/.fvwmrc exists
	echo &#8220;you have a .fvwmrc file&#8221;
	if [ -L "${HOME}/.fvwmrc" ]; then 		# is it a symlink ?
		echo &#8220;it&#8217;s a symbolic link
	elif [ -f "${HOME}/.fvwmrc" ]; then 	# is it a regular file ?
		echo &#8220;it&#8217;s a regular file&#8221;
	fi
else
	echo &#8220;you have no .fvwmrc file&#8221;
fi</pre> </p>
<p><H4>Some pitfalls to be wary of</H4><br />
The test command needs to be in the form<br />
&#8220;<code>operand1 &lt;space&gt; operator &lt; space &gt; operand2</code>&#8221; or<br />
<code>operator &lt;space&gt; operand2</code> , in other words you really <EM>need</EM> these spaces, since the shell considers the first block containing no spaces to be either an operator (if it begins with a &#8216;-&#8217;) or an operand (if it doesn&#8217;t). So for example; this:<br />
<PRE>if [ 1=2 ]; then
	echo &#8220;hello&#8221;
fi
</pre> </p>
<p>gives exactly the &#8220;wrong&#8221; output (ie it echos &#8220;hello&#8221;, since it sees an operand but no operator.) </p>
<p>Another potential trap comes from not protecting variables in quotes. We have already given an example as to why you <EM>must</EM> wrap anything you wish to use for a <CODE>-n</CODE> test with quotes. However, there are a lot of good reasons for using quotes all the time, or almost all of the time. Failing to do this when you have variables expanded inside tests can result in <EM>very</EM><br />
wierd bugs. Here&#8217;s an example:<br />
<PRE>#!/bin/bash
X=&#8221;-n&#8221;
Y=&#8221;"
if [ $X = $Y ] ; then
	echo &#8220;X=Y&#8221;
fi
</pre> </p>
<p>This will give misleading output since the shell expands our expression to:</p>
<p>[ -n = ] </p>
<p>and the string &#8220;=&#8221; has non zero length. </p>
<p><H4>A brief summary of test operators</H4></p>
<p>Here&#8217;s a quick list of test operators. It&#8217;s by no means comprehensive, but its likely to be all you&#8217;ll need to remember (if you need anything else, you can always check the bash manpage &#8230; )</p>
<p><strong>WordPress css theme bonked table.  Please scroll down.</strong><br />
<TABLE cellPadding="5" border="5"><br />
  <TBODY><br />
  <TR><br />
    <TD>operator</TD><br />
    <TD>produces true if&#8230; </TD><br />
    <TD>number of operands</TD></TR><br />
  <TR><br />
    <TD>-n</TD><br />
    <TD>operand non zero length</TD><br />
    <TD>1</TD></TR><br />
  <TR><br />
    <TD>-z</TD><br />
    <TD>operand has zero length</TD><br />
    <TD>1</TD></TR><br />
  <TR><br />
    <TD>-d</TD><br />
    <TD>there exists a directory whose name is <EM>operand</EM></TD><br />
    <TD>1</TD></TR><br />
  <TR><br />
    <TD>-f</TD><br />
    <TD>there exists a file whose name is <EM>operand</EM></TD><br />
    <TD>1</TD></TR><br />
  <TR><br />
    <TD>-eq</TD><br />
    <TD>the operands are integers and they are equal</TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>-neq</TD><br />
    <TD>the opposite of -eq</TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>=</TD><br />
    <TD>the operands are equal (as strings)</TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>!=</TD><br />
    <TD>opposite of = </TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>-lt</TD><br />
    <TD><EM>operand1</EM> is strictly less than <EM>operand2</EM> (both<br />
      operands should be integers)</TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>-gt</TD><br />
    <TD><EM>operand1</EM> is strictly greater than <EM>operand2</EM> (both<br />
      operands should be integers)</TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>-ge</TD><br />
    <TD><EM>operand1</EM> is greater than or equal to <EM>operand2</EM> (both<br />
      operands should be integers)</TD><br />
    <TD>2</TD></TR><br />
  <TR><br />
    <TD>-le</TD><br />
    <TD><EM>operand1</EM> is less than or equal to <EM>operand2</EM> (both<br />
      operands should be integers)</TD><br />
    <TD>2</TD></TR></TBODY></TABLE></p>
<p><H3>Loops </H3></p>
<p>Loops are constructions that enable one to reiterate a procedure or perform the same procedure on several different items. There are the following kinds of loops available in bash:<br />
<UL><br />
  <LI>for loops<br />
  <LI>while loops</LI></UL><br />
<H4>For loops</H4><br />
The syntax for the for loops is best demonstrated by example:<br />
<PRE>#!/bin/bash
for X in red green blue
do
	echo $X
done</pre> </p>
<p>The for loop iterates the loop over the space separated items. Note that if some of the items have embedded spaces, you need to protect them with quotes. Here&#8217;s an example:<br />
<PRE>#!/bin/bash
colour1=&#8221;red&#8221;
colour2=&#8221;light blue&#8221;
colour3=&#8221;dark green&#8221;
for X in &#8220;$colour1&#8243; $colour2&#8243; $colour3&#8243;
do
	echo $X
done
</pre> </p>
<p>Can you guess what would happen if we left out the quotes in the for statement? This indicates that variable names should be protected with quotes unless you are pretty sure that they do not contain any spaces.</p>
<p><H4>Globbing in for loops</H4><br />
The shell expands a string containing a * to all filenames that &#8220;match&#8221;. A filename matches if and only if it is identical to the match string after replacing the stars * with arbitrary strings. For example, the character &#8220;*&#8221; by itself expands to a space separated list of all files in the working directory (excluding those that start with a dot &#8220;.&#8221; ) So,</p>
<p><code>echo *</code> </p>
<p>lists all the files and directories in the current directory,</p>
<p><code>echo *.jpg</code></p>
<p>lists all the jpeg files, and</p>
<p><code>echo ${HOME}/public_html/*.jpg</code></p>
<p>lists all jpeg files in your public_html directory. </p>
<p>As it happens, this turns out to be very useful for performing operations on<br />
the files in a directory, especially used in conjunction with a for loop. For<br />
example:<br />
<PRE>#!/bin/bash
for X in *.html
do
		grep -L &#8216;&lt;UL&gt;&#8217; &#8220;$X&#8221;
done</pre> </p>
<p><H4>While Loops</H4><br />
While loops loop &#8220;while&#8221; a given condition remains true. An example of this:<br />
<PRE>#!/bin/bash
X=0
while [ $X -le 20 ]
do
	echo $X
	X=$((X+1))
done</pre> </p>
<p>This raises a natural question, why doesn&#8217;t bash allow the C like for loops?<br />
<PRE>for (X=1,X&lt;10; X++)</pre> </p>
<p>As it happens, this is discouraged for a reason: bash is an interpreted language, and a rather slow one for that matter. For this reason, heavy iteration is discouraged. </p>
<p><H3>Command Substitution</H3></p>
<p>Command Substitution is a very handy feature of the bash shell. It enables you to take the output of a command and treat it as though it was written on the command line. For example, if you want to set the variable X to the output of a command, the way you do this is via command substitution. </p>
<p>There are two means of command substitution: brace expansion and backtick<br />
expansion. </p>
<p>Brace expansion works as follows: <CODE>$(<EM>commands</EM>)</CODE> expands<br />
to the output of <EM>commands</EM> This permits nesting, so <EM>commands</EM><br />
can include brace expansions </p>
<p>Backtick expansion expands <CODE>`<EM>commands</EM>`</CODE> to the output of <EM>commands</EM>,</p>
<p>An example is given:<br />
<PRE>#!/bin/bash
files=&#8221;$(ls )&#8221;
web_files=`ls public_html`
echo $files
echo $web_files
X=`expr 3 \* 2 + 4` # expr evaluate arithmetic expressions. man expr for details.
echo $X</pre> </p>
<p>Note that even though the output of ls contains newlines, the variables do not. Bash variables can not contain newline characters (which is a pain in the butt. But that&#8217;s life) Anyway, the advantage of the $() substitution method is almost self evident: it is very easy to nest. It is supported by most of the bourne shell variants (the POSIX shell or better is OK). However, the backtick substitution is slightly more readable, and is supported by even the most basic shells (any #!/bin/sh version is just fine) </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/423/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/423/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/423/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=423&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/06/05/quick-guide-to-writing-scripts-repub/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/toddpartridge-128.jpg" medium="image">
			<media:title type="html">toddpartridge</media:title>
		</media:content>
	</item>
		<item>
		<title>Uni-no-code</title>
		<link>http://linuxtidbits.wordpress.com/2008/06/04/uni-no-code/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/06/04/uni-no-code/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 18:07:31 +0000</pubDate>
		<dc:creator>Todd Partridge</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=421</guid>
		<description><![CDATA[Because my laptop is getting older my ethernet and wireless hardware has failed on me so I&#8217;m relagated to downloading the webpages I want to read at the library.  I don&#8217;t complain, this actually works just fine for me.  Firefox though cannot open multiple pages at once:
firefox *.htm
So I built a script that [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Because my laptop is getting older my ethernet and wireless hardware has failed on me so I&#8217;m relagated to downloading the webpages I want to read at the library.  I don&#8217;t complain, this actually works just fine for me.  Firefox though cannot open multiple pages at once:</p>
<pre>firefox *.htm</pre>
<p>So I built a script that does so:</p>
<pre>#!/bin/bash
# firefox to open all .htm, .html files

for X in *.htm
do
    firefox "$X"
done

for Y in *.html
do
    firefox "$Y"
done</pre>
<p>Only problem is, XP doesn&#8217;t write unicode so Firefox will complain that it can&#8217;t find the file when it encounters a character it doesn&#8217;t understand.  Unknown characters in Unicode will map as &#8220;ï¿½&#8221;.  This may not translate well on WordPress, or the Browser, or the OS you&#8217;re using so here&#8217;s a pic:</p>
<p><img src="http://linuxtidbits.files.wordpress.com/2008/06/xp-no-unicode.jpg" alt="XP Uni-no-code" /></p>
<p>For any developers out there, do you have an idea how to write a script to rewrite the filenames so they are Unicode (or remove the un-unicode lettering) without having to manually type in each name?</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/421/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/421/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/421/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=421&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/06/04/uni-no-code/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/toddpartridge-128.jpg" medium="image">
			<media:title type="html">toddpartridge</media:title>
		</media:content>

		<media:content url="http://linuxtidbits.files.wordpress.com/2008/06/xp-no-unicode.jpg" medium="image">
			<media:title type="html">XP Uni-no-code</media:title>
		</media:content>
	</item>
		<item>
		<title>A Walk with PCMan</title>
		<link>http://linuxtidbits.wordpress.com/2008/06/02/a-walk-with-pcman/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/06/02/a-walk-with-pcman/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 16:35:49 +0000</pubDate>
		<dc:creator>Todd Partridge</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=418</guid>
		<description><![CDATA[A few months ago, I had tripped upon a post in Ubuntu&#8217;s forums that the PCMan file browser was restarting development and became a bit curious.  A year or two ago there have been postings that I had seen in the Gentoo forums about how good a lightweight file browser it was.  Then [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://flickr.com/photos/thorstenvpk/1287205747/in/photostream/"><img src="http://farm2.static.flickr.com/1171/1287205747_4bfca93a7b.jpg?v=0" alt="A Walk with PCMan" align="left" style="margin:0 10px 5px 0;" /></a>A few months ago, I had tripped upon a post in Ubuntu&#8217;s forums that the PCMan file browser was restarting development and became a bit curious.  A year or two ago there have been postings that I had seen in the Gentoo forums about how good a lightweight file browser it was.  Then yesterday, I saw that <a href="http://tombuntu.com/index.php/2008/05/29/pcman-lightweight-alternative-file-manager/">Tombuntu</a> had an overview of the new PCMan and then I just happened to see an <a href="http://www.void.gr/kargig/blog/2008/05/29/pcmanfm-0411-ebuild/">ebuild</a> made for it. So I decided to give it a try.</p>
<p>Currently, I use the brute horse (Nautilus) for file browsing.  Nautilus is a really good browser but on this old klunker it cold-starts in 15 seconds and warm-starts in five and it would be nice if I could find something quicker.  <a href="http://linuxtidbits.wordpress.com/2008/01/14/thunar-for-nautilus/">Before</a>, I have replaced Nautilus with Thunar as the default browser, but Nautilus caught up a lot in speed when I removed the Enlightenment Sound Daemon as a variable, and frankly I had just become too lazy to change it back when I updated to Gnome 2.22.</p>
<p>The <a href="http://www.void.gr/kargig/blog/2008/05/29/pcmanfm-0411-ebuild/">ebuild</a> compiled PCMan painlessly - thanks George for the update.  For the ebuild UsE flags, I built with and without the &#8216;desktop&#8217; flag.  The ebuild notes the desktop flag as &#8216;desktop integration&#8217; but I didn&#8217;t notice a difference either way.  Perhaps it is for desktop-less installs (fluxbox,&#8230;).  The &#8216;fam&#8217; flag is necessary for file monitoring support, it works in conjunction with gamin which is already built along with Gnome.  Also, I took out the confirm delete patch as PCMan-4 has a confirm dialog when deleting a file/folder (I&#8217;m guessing the patch was for PCMan-3.*).</p>
<p>I found PCMan&#8217;s menu entry in &#8216;System Tools&#8217; and loaded PCMan.  PCMan cold-started in about 5 seconds.</p>
<p><img src="http://linuxtidbits.files.wordpress.com/2008/06/pcman-boot.jpg" alt="Pic PCMan boot" /></p>
<p>Beginning thoughts: I liked PCMan.  First, PCMan recognized my GTK and icon theme and also recognized the bookmarks I previously made in Nautilus.  Big pluses.  PCMan feels alot like Nautilus which is great because I am used to Nautilus&#8217;s behavior.  The response time was nice as well (changing from one folder to the next took about one second).  Picture previews are a must for me and PCMan did that just fine.  PCMan also has tabbed browsing.  I heard about this coming to Nautilus 2.24 and I like the thought of it.  PCMan has the ability to drag between tabs and the ability to reorder tabs, very nice.</p>
<p><img src="http://linuxtidbits.files.wordpress.com/2008/06/pcman-nautilus-comparision.jpg" alt="A Walk with PCMan" /></p>
<p><a href="http://www.ubuntugeek.com/how-to-replace-nautilus-with-pcman-file-manager-in-ubuntu.html">Ubuntugeek</a> has a post that will launch PCMan for folder&#8217;s in the Place&#8217;s Listing in the Gnome Menu.  I could probably use the Thunar script I previously used and link /usr/bin/nautilus to make PCman my default browser but I don&#8217;t feel like doing the work - be lost on the next update anyhow.  Besides, I want to keep Nautilus as my desktop browser because it does a damn good job at it.  For now I&#8217;m going to keep using PCMan and be content on opening folders on the desktop by right-clicking them and choosing PCMan.  Lightweight desktops should think about giving PCMan a try.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/418/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/418/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/418/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=418&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/06/02/a-walk-with-pcman/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/toddpartridge-128.jpg" medium="image">
			<media:title type="html">toddpartridge</media:title>
		</media:content>

		<media:content url="http://farm2.static.flickr.com/1171/1287205747_4bfca93a7b.jpg?v=0" medium="image">
			<media:title type="html">A Walk with PCMan</media:title>
		</media:content>

		<media:content url="http://linuxtidbits.files.wordpress.com/2008/06/pcman-boot.jpg" medium="image">
			<media:title type="html">Pic PCMan boot</media:title>
		</media:content>

		<media:content url="http://linuxtidbits.files.wordpress.com/2008/06/pcman-nautilus-comparision.jpg" medium="image">
			<media:title type="html">A Walk with PCMan</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick Tips</title>
		<link>http://linuxtidbits.wordpress.com/2008/05/27/quick-tips/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/05/27/quick-tips/#comments</comments>
		<pubDate>Tue, 27 May 2008 16:13:12 +0000</pubDate>
		<dc:creator>Dirk Gently</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=416</guid>
		<description><![CDATA[
Hello blogosphere!  As I&#8217;m working on putting my bash scripts together, here&#8217;s a few quick tips that one may use in everyday life.
Background Command
Ever started a program in the terminal because it doesn&#8217;t have a menu listing, or need to see it&#8217;s error output and then realize later that you need the terminal?  [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://flickr.com/photos/thorstenvpk/1287205747/in/photostream/"><img src="http://farm2.static.flickr.com/1171/1287205747_4bfca93a7b.jpg?v=0" alt="Linux Quick Tips" align="left" style="margin:0 10px 5px 0;" /></a><br />
Hello blogosphere!  As I&#8217;m working on putting my bash scripts together, here&#8217;s a few quick tips that one may use in everyday life.</p>
<p><strong>Background Command</strong></p>
<p>Ever started a program in the terminal because it doesn&#8217;t have a menu listing, or need to see it&#8217;s error output and then realize later that you need the terminal?  Opening another tab is simple enough but you really don&#8217;t need the program hogging the terminal anymore.  Well, there is a way to do this.</p>
<p>Previously, people may have viewed my <a href="http://linuxtidbits.wordpress.com/2008/02/01/background-a-process/">bash script</a> that can start programs in the terminal in the background.  Already running applications can be backgrounded as well.  First type ctrl-Z to release the application, then using the <code>bg</code> program will background it&#8217;s output.</p>
<p><img src="http://linuxtidbits.files.wordpress.com/2008/05/bg.jpg" /></p>
<p><strong>Gnome&#8217;s Middle-Click, Title-Bar Trick</strong></p>
<p>For the long time I&#8217;ve been using Gnome and just learned about this one.  A quick way to look at a window below the current on is to middle-click on title bar.  <em>Voila! The current window izzz lowered.</em>  More tricks can be found on <a href="http://live.gnome.org/DocumentationProject/TipsAndTricks">Gnome Tip&#8217;s and Tricks</a> page.</p>
<p><strong>Firefox Hunt</strong></p>
<p>I have the tendency that once I&#8217;m on the keyboard, I like to stay on the keyboard, so doing a search in Firefox by going to the mouse selecting the search engine, and typing in the field seems like extra legwork to me.  To do a fast search in Firefox on the keyboard is as easy as: ctrl-K to move to the search box and alt-up/down to select the search engine.</p>
<p><strong>Grep Two Search Terms</strong></p>
<p>On the occasion that a grep search needs to look for two words, egrep it:</p>
<pre>egrep -w 'word1|word2' /path/to/file</pre>
<p><strong>Fox in Hounds Teeth</strong></p>
<p>This is personal advice, but take it from me - worth it.  Don&#8217;t use Foxmarks Bookmarks Synchronizing Service.  I used this service as I sold my old computer when I got the new.  I trusted this service to hold my web bookmarks and&#8230; it didn&#8217;t.  It errored with the line, &#8220;Can&#8217;t synchronize bookmarks, transfer error.&#8221;  I asked about the error and only got the explanation that, &#8220;&#8230;this sometimes happens&#8221;.  Also I got no explanation on why or what happened to their backup service.</p>
<p>There&#8217;s another Bookmark Synchronizer out there but for the life of me can&#8217;t remember the name of it.  Anyone?</p>
<p><strong>Thunar Custom Actions</strong></p>
<p>Thunar has the ability to create custom scripts built directly into it.  For the most part it&#8217;s self explanatory.  For greater degree of difficultly scripts, here&#8217;s the <a href="http://thunar.xfce.org/pwiki/documentation/custom_actions">documentation</a>.</p>
<p>Have a Good Day! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/416/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/416/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/416/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=416&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/05/27/quick-tips/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/dirkrgently-128.jpg" medium="image">
			<media:title type="html">Dirk R. Gently</media:title>
		</media:content>

		<media:content url="http://farm2.static.flickr.com/1171/1287205747_4bfca93a7b.jpg?v=0" medium="image">
			<media:title type="html">Linux Quick Tips</media:title>
		</media:content>

		<media:content url="http://linuxtidbits.files.wordpress.com/2008/05/bg.jpg" medium="image" />
	</item>
		<item>
		<title>Gentoo Scripts&#8230; as promised.</title>
		<link>http://linuxtidbits.wordpress.com/2008/05/20/gentoo-scripts-as-promised/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/05/20/gentoo-scripts-as-promised/#comments</comments>
		<pubDate>Tue, 20 May 2008 16:21:00 +0000</pubDate>
		<dc:creator>Dirk Gently</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=415</guid>
		<description><![CDATA[Has a bit of a Yogi Bear thing, don&#8217;t ya think?


I tried to sleep a few nights back and my ears just wouldn&#8217;t leave me alone, so I thought lets boot my computer and see if there is anything still useful on it.  So I began to look through my ~/.bin/ directory and dug [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><img src="http://linuxtidbits.files.wordpress.com/2008/03/gentoo-header.png" style="border-width:0;margin:0 10px 5px 0;" align="left" alt="coreutils and mktemp a dangerous pair" />Has a bit of a Yogi Bear thing, don&#8217;t ya think?</p>
<p></p>
<p><img src="http://farm1.static.flickr.com/15/18759891_b93f228a82_m.jpg" style="border-width:0;margin:0 10px 5px 0;" align="right" alt="coreutils and mktemp a dangerous pair" /></p>
<p>I tried to sleep a few nights back and my ears just wouldn&#8217;t leave me alone, so I thought lets boot my computer and see if there is anything still useful on it.  So I began to look through my <code>~/.bin/</code> directory and dug up a few things.  I&#8217;ll post a few of these in the next few days..</p>
<h3>Gentoo scripts</h3>
<p>I&#8217;m not a typical Gentooee where: while, if, and C daemons are popular but I have a couple hat tricks that did what I needed them to do.</p>
<h4>Archive and Delete</h4>
<p>This computer has a 5GB hard drive for which is about the bare min to run a Linux desktop with (even trickier with Portage).  So often I try a program and say, &#8220;Ok, I can use that but I won&#8217;t be very often.&#8221;  So this script I made to archive the package and back it up to my flash drive:</p>
<p><strong>archive-wipe</strong></p>
<pre>#!/bin/bash
# archive-wipe - create archive of package and remove from system

PACKAGE=$1
#ARCHIVEDPACKAGECHECK=/media/disk/portage-packages/All/${PACKAGE.*}
#ARCHIVEDPACKAGENAME=${ls /media/disk/portage-packages/All | grep $PACKAGE}
# -CAT/PACAGE

if [[ -z $PACKAGE ]]; then
    echo "archive-wipe "
    exit;
fi

# Gnome volume manager will at times put the drive on disk-[1-10]
if grep "/dev/uba1.*/media/disk-.*" /etc/mtab; then
    echo " * Drive mounted incorrectly.  Exiting."
    exit; else
    echo " * Archiving $PACKAGE"
    sudo quickpkg --include-config=y "$PACKAGE" &amp;&amp; echo " * '$PACKAGE' archived, unmerging from portage." &amp;&amp; sudo emerge -C "$PACKAGE"
#    if [ -z ARCHIVEDPACKAGECHECK ]; then
#    if "$ARCHIVEDPACKAGEDNAME"; then
#    if ls /media/disk/portage-packages/All | grep "$PACKAGE"; then
#    if [ -z "/media/disk/portage-package/All/${PACKAGE%.*}" ]; then
#        echo " * '$ARCHIVEDPACKAGENAME' archived, unmerging from portage."
#        echo " *** "$PACKAGE" has not been archived.  Exiting"
#        exit;
#    fi
fi</pre>
<h4>ebuild2overlay</h4>
<p>I&#8217;ve wrote before about <a href="/2008/03/13/ebuild-2-overlay-version-two/">ebuild2overlay</a>.  I find myself using this quite a bit.  When a program I need/want isnt&#8217; in Portage, someone if often good enough to have written an ebuild for in and put it in Gentoo&#8217;s Bugzilla.</p>
<p>I&#8217;ve made a few small updates to the script and updated the post.</p>
<p>For any that change of modify this script, please let me know about it.  I also would enjoy hearing any thoughts.</p>
<h4>unblock-package</h4>
<p>This one I got from the Gentoo wiki and it altered slightly it use quickpkg so the blocker doesn&#8217;t have to be recompiled:</p>
<pre>#!/bin/bash

BLOCKER=$1
BLOCKED=$2

if [[ -z $BLOCKED ]]; then
    echo " unblock-package  "
    echo " * Use category/package."
    exit;
fi

#sudo emerge --buildpkgonly --nodeps $BLOCKED &amp;&amp; i
sudo quickpkg $BLOCKER &amp;&amp; sudo emerge -C $BLOCKER &amp;&amp; sudo emerge -K --nodeps $BLOCKED

# Possible?
# emerge --resume</pre>
<h4>gentoo-update</h4>
<p>This is my Gentoo update world script.  It asks if it should start with a pretend emerge, emerges, revdep-rebuilds, and dep-cleans.  I&#8217;ve seen a better one on the forums but I was never able to find it again.</p>
<pre>#!/bin/bash
# gentoo-update - world update and configure

TXT_YL="tput setaf 3" #
TXT_RESET="tput sgr0"

sleep 1 &amp;&amp; echo " * Gentoo world update starting."
sleep 2 &amp;&amp; echo " * Does the Portage tree need updated? (y/N)"

read SYNCPORTAGE

if [ "$SYNCPORTAGE" == y ]; then
    sleep 2
    echo " * Please wait and as the Portage tree is updated."
    sudo eix-sync &amp;&amp; sudo pmaint sync
    sleep 2 &amp;&amp; echo " * Portage tree updated."
fi

sleep 1 &amp;&amp; echo " * Standard or tree view to display pretend information? (s/t/Neither)"

read PRETEND

if [ $PRETEND == s ]; then
    sleep 2 &amp;&amp; echo " * Running pretend infomation."
    sleep 2 &amp;&amp; echo " * This can take awhile, please be patient."
    emerge --update --newuse --deep -pv --color y world | less -R
    #pmerge --upgrade --deep --pretend --set world | less -R
    sleep 2 &amp;&amp; echo " * Review the infomation, if anything needs changed now's the time to do it."
fi

if [ $PRETEND == t ]; then
    sleep 2 &amp;&amp; echo " * Running pretend infomation."
    sleep 2 &amp;&amp; echo " * This can take awhile, please be patient."
    sleep 2 &amp;&amp; echo " * Review the infomation, if anything needs changed now's the time to do it."
#    emerge --update --newuse --deep --tree -pv --color y world | less -R
    emerge --update --newuse --deep --tree -pv --color y world | ansi2html &gt; /tmp/gentoo-update-tree.html
    epiphany --new-tab /tmp/gentoo-update-tree.html
fi

sleep 1
echo " * Update Gentoo? (y/N)"
read UPDATEGENTOO

if [ "$UPDATEGENTOO" == y ];then
#    sudo pmerge --upgrade --deep --set world &amp;&amp;
    sudo emerge --update --newuse --deep world &amp;&amp; sudo dispatch-conf &amp;&amp; sudo emerge --depclean &amp;&amp; sudo revdep-rebuild -pv; else
    exit
fi</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/415/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/415/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/415/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=415&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/05/20/gentoo-scripts-as-promised/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/dirkrgently-128.jpg" medium="image">
			<media:title type="html">Dirk R. Gently</media:title>
		</media:content>

		<media:content url="http://linuxtidbits.files.wordpress.com/2008/03/gentoo-header.png" medium="image">
			<media:title type="html">coreutils and mktemp a dangerous pair</media:title>
		</media:content>

		<media:content url="http://farm1.static.flickr.com/15/18759891_b93f228a82_m.jpg" medium="image">
			<media:title type="html">coreutils and mktemp a dangerous pair</media:title>
		</media:content>
	</item>
		<item>
		<title>Have fingers, will post&#8230;</title>
		<link>http://linuxtidbits.wordpress.com/2008/05/05/have-fingers-will-post/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/05/05/have-fingers-will-post/#comments</comments>
		<pubDate>Mon, 05 May 2008 22:15:37 +0000</pubDate>
		<dc:creator>Dirk Gently</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=414</guid>
		<description><![CDATA[Hello blogosphere!
Dirk has bumped into a mild setback as beasty laptop seems to have failed on him.  Actually the laptop is perfectly fine but the network (both ethernet and wifi) have complete gone.  Currently obligations hold me liable, obscuring a new beasty, so I reach out to the net so see if any [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://flickr.com/photos/thorstenvpk/1287205747/in/photostream/"><img src="http://farm2.static.flickr.com/1171/1287205747_4bfca93a7b.jpg?v=0" alt="Have fingers, will post..." align="left" style="margin:0 10px 5px 0;" /></a>Hello blogosphere!</p>
<p>Dirk has bumped into a mild setback as beasty laptop seems to have failed on him.  Actually the laptop is perfectly fine but the network (both ethernet and wifi) have complete gone.  Currently obligations hold me liable, obscuring a new beasty, so I reach out to the net so see if any help is avail.</p>
<p>I&#8217;d like a basic laptop.  Any day or age will probably do.  As long as it&#8217;s able to connect to the internet and run linux.  If anyone has such, I&#8217;d appreciate the help.  Address is:</p>
<p>T.R.<br />
816 MacFarlane Rd.<br />
Portage, WI 53901</p>
<p>I miss blogging greatly and hope there someone out there that can help.  I may be able to help with P.O. cost.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/414/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/414/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/414/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=414&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/05/05/have-fingers-will-post/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/dirkrgently-128.jpg" medium="image">
			<media:title type="html">Dirk R. Gently</media:title>
		</media:content>

		<media:content url="http://farm2.static.flickr.com/1171/1287205747_4bfca93a7b.jpg?v=0" medium="image">
			<media:title type="html">Have fingers, will post...</media:title>
		</media:content>
	</item>
		<item>
		<title>Auf Wiedersehen and all the fish, I&#8217;ll be back.</title>
		<link>http://linuxtidbits.wordpress.com/2008/04/22/auf-wiedersehen-and-all-the-fish-ill-be-back/</link>
		<comments>http://linuxtidbits.wordpress.com/2008/04/22/auf-wiedersehen-and-all-the-fish-ill-be-back/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 20:08:27 +0000</pubDate>
		<dc:creator>Dirk Gently</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://linuxtidbits.wordpress.com/?p=413</guid>
		<description><![CDATA[Hello Blogosphere.
Thank you for reading these last six months. Because of events in my life, I am not sure if I&#8217;ll be able to post again anytime soon, but I hope to do.  For those that don&#8217;t know, I&#8217;ve been the subject of a culture that is trying (in their own words) to &#8220;assimilate&#8221; [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Hello Blogosphere.</p>
<p>Thank you for reading these last six months. Because of events in my life, I am not sure if I&#8217;ll be able to post again anytime soon, but I hope to do.  For those that don&#8217;t know, I&#8217;ve been the subject of a culture that is trying (in their own words) to &#8220;assimilate&#8221; me into their beliefs and habits.  Because they love this culture so much they will do anything to defend it including breaking the law (and not just a bit) and terrorism.  I don&#8217;t mind this culture without these facets.  I even see alot of benefit in it.  But besides these reasons if they are not enough, here are a few more: personal experiences have taught me in this culture that force is more rewarded than &#8220;observation then action&#8221;, that taking chances without concern for the greater good is not only allowed but encouraged, that saying, &#8220;I don&#8217;t care&#8221; is vastly greater than saying, &#8220;I&#8217;d like to help&#8221;.  </p>
<p>So here&#8217;s to choice, here&#8217;s to our own discretions, here&#8217;s to technology without terror.  Here&#8217;s to the &#8220;1&#8217;s&#8221; and the &#8220;a&#8217;s&#8221;.</p>
<p>&#8220;&#8230;-Ism&#8217;s in my opinion are not good. A person should not believe in an -ism, he should believe in himself.&#8221;</p>
<p>&#8211;John Lennon</p>
<p>&#8220;Maybe after another three years, I&#8217;ll get my freedom back.</p>
<p>The Great Escape</p>
<p>&#8220;They put female hormone in my drinking supply&#8221;</p>
<p>Real Genius</p>
<p>&#8220;Be GOOD to one another&#8221;</p>
<p>Bill and Ted&#8217;s Excellent Adventure</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/linuxtidbits.wordpress.com/413/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/linuxtidbits.wordpress.com/413/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/linuxtidbits.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/linuxtidbits.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/linuxtidbits.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/linuxtidbits.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/linuxtidbits.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/linuxtidbits.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/linuxtidbits.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/linuxtidbits.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/linuxtidbits.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/linuxtidbits.wordpress.com/413/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=linuxtidbits.wordpress.com&blog=1210515&post=413&subd=linuxtidbits&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://linuxtidbits.wordpress.com/2008/04/22/auf-wiedersehen-and-all-the-fish-ill-be-back/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/dirkrgently-128.jpg" medium="image">
			<media:title type="html">Dirk R. Gently</media:title>
		</media:content>
	</item>
	</channel>
</rss>