<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-12495806</id><updated>2011-11-30T23:16:48.953-08:00</updated><title type='text'>Bash Rules</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>69</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-12495806.post-5884183679931684901</id><published>2007-07-03T00:20:00.001-07:00</published><updated>2007-07-03T00:27:15.570-07:00</updated><title type='text'>Whats your background?</title><content type='html'>As part of job control its possible to stop a process and continue it later.&lt;br /&gt;So while you are running a program, you can type Ctrl-Z to suspend it , its like a pause in a media player&lt;br /&gt;&lt;br /&gt;Then you can ask bash to continue the process in background by typing 'bg'. &lt;br /&gt;Background processes can not read from terminal and if they try to they will be suspended(paused).&lt;br /&gt;&lt;br /&gt;Here is quick test for this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;bash$ cat read.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;sleep 5&lt;br /&gt;echo -n "Enter some text &gt; "&lt;br /&gt;read text&lt;br /&gt;echo "You entered: $text"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Run the  script and hit Ctrl-Z&lt;br /&gt;&lt;code&gt;&lt;br /&gt;bash$ ./read.sh&lt;br /&gt;&lt;br /&gt;[1]+  Stopped                 ./read.sh&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now run this in background using bg command.&lt;br /&gt;&lt;br /&gt;You are prompted to enter some text&lt;br /&gt;&lt;code&gt;&lt;br /&gt;bash$ bg&lt;br /&gt;[1]+ ./read.sh &amp;&lt;br /&gt;bash$ Enter some text &gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;As soon as you enter some text and hit Enter you will see this &lt;br /&gt;&lt;code&gt;&lt;br /&gt;bash$ Enter some text &gt;&lt;br /&gt;&lt;br /&gt;[1]+  Stopped                 ./read.sh&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Any more attempts to run this in backgroup will suspend the script.&lt;br /&gt;Run fg to get the script to run in foreground to get out of this loop.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;bash$ bg&lt;br /&gt;[1]+ ./read.sh &amp;&lt;br /&gt;&lt;br /&gt;[1]+  Stopped                 ./read.sh&lt;br /&gt;bash$ bg&lt;br /&gt;[1]+ ./read.sh &amp;&lt;br /&gt;&lt;br /&gt;[1]+  Stopped                 ./read.sh&lt;br /&gt;bash$ bg&lt;br /&gt;[1]+ ./read.sh &amp;&lt;br /&gt;&lt;br /&gt;[1]+  Stopped                 ./read.sh&lt;br /&gt;bash$ fg&lt;br /&gt;./read.sh&lt;br /&gt;hi there&lt;br /&gt;You entered: hi there&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-5884183679931684901?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/5884183679931684901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=5884183679931684901' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/5884183679931684901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/5884183679931684901'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2007/07/whats-your-background.html' title='Whats your background?'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-116728864636266125</id><published>2006-12-27T22:49:00.000-08:00</published><updated>2006-12-27T22:58:40.236-08:00</updated><title type='text'>Reviewing Sed - Part 1</title><content type='html'>There is a good collection of sed one liners at http://www.student.northpark.edu/pemente/sed/sed1line.txt.&lt;br /&gt;&lt;br /&gt;So I have just begun to review few them using sed manpage because of the earthquake in Taiwan.&lt;br /&gt;&lt;br /&gt;# Following line will insert a blank space after everyline in temp.txt&lt;br /&gt;&lt;code&gt;&lt;br /&gt; sed G temp.txt&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;G  -  Append hold space to pattern space.&lt;br /&gt;&lt;br /&gt;So hold space holds nothing initially and if you append that to pattern space, you get a new line.&lt;br /&gt;&lt;br /&gt;So thats the way to add blank lines after everyline. &lt;br /&gt;Sed goes through each line and loads it to the pattern space.&lt;br /&gt;&lt;br /&gt;# Adds only a single blank line to all lines to temp.txt&lt;br /&gt;&lt;code&gt;&lt;br /&gt;sed '/^$/d;G' temp.txt&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;/regexp/ - Match lines matching the regular expression regexp.&lt;br /&gt;&lt;br /&gt;   d     - Delete pattern space.  Start next cycle.&lt;br /&gt;&lt;br /&gt;There are two things to consider.&lt;br /&gt;For blank lines : 'd' is executed that deletes the pattern space and starts next cycle(loads next line and starts all over again)&lt;br /&gt;&lt;br /&gt;For non blank lines : as the pattern doesn't match, d is not executed and next command G gets executed.&lt;br /&gt;We get a blank line after every non blank line.&lt;br /&gt;&lt;br /&gt;The command would delete the blank lines and skip the G command for blank lines.&lt;br /&gt;Thing to note is that d command applies only to lines matching the regex /^$/ whereas &lt;br /&gt;G command applies to all lines and is not tied to the regex. However when regex is matched the d command will cause G command to be skipped.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-116728864636266125?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/116728864636266125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=116728864636266125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116728864636266125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116728864636266125'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/12/reviewing-sed-part-1.html' title='Reviewing Sed - Part 1'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-116599834205195608</id><published>2006-12-13T00:23:00.000-08:00</published><updated>2006-12-25T22:32:23.233-08:00</updated><title type='text'>Sed and No DuPlication</title><content type='html'>I needed to remove duplicate names from a file so I thought sed should be a good choice for it.&lt;br /&gt;&lt;code&gt;uniq&lt;/code&gt; is too easy so I found out how sed does it. Herez &lt;a href="http://www.student.northpark.edu/pemente/sed/sed1line.txt"&gt;how&lt;/a&gt; &lt;br /&gt;&lt;code&gt;&lt;br /&gt;$  sed '$!N; /^\(.*\)\n\1$/!P; D' filename&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;So now time for an explanation.&lt;br /&gt;&lt;br /&gt;1 &lt;code&gt;$!N&lt;/code&gt; - sed reads one line at a time and then works on it. It doesn't read in the newline at the end of the line into pattern space (what sed works on). So N command appends the newline and the next line to the pattern space.&lt;br /&gt;$ denotes the last line and ! means NOT, so it means for the last line don't execute N command.Heck as if there is anything to read after the last line..read it if you can for all I care.&lt;br /&gt;&lt;br /&gt;2. &lt;code&gt;/^\(.*\)\n\1$/!P;&lt;/code&gt; - If you see start of pattern space and then anything followed by a newline which is followed by exactly that anything. Don't "print the first part of pattern space till the newline"(P) else print first part of pattern space till the newline&lt;br /&gt;&lt;br /&gt;3. &lt;code&gt;D&lt;/code&gt; - "just delete the first part of pattern space till the newline and restart the command cycle i.e go back to N"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-116599834205195608?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/116599834205195608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=116599834205195608' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116599834205195608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116599834205195608'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/12/sed-and-no-duplication.html' title='Sed and No DuPlication'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-116556619480106374</id><published>2006-12-08T00:19:00.000-08:00</published><updated>2006-12-08T00:24:27.746-08:00</updated><title type='text'>Its time for tee</title><content type='html'>I was asked this question and suddenly i realized that bash doesnt have redirection like operator to do this. Do what? Print Standard Output/Error as it is and also redirect it to a file. So therefore its time for tee.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ls i_dont_exist 2&gt;&amp;1 | tee output.txt&lt;br /&gt;ls: i_dont_exist: No such file or directory&lt;br /&gt;$cat output.txt&lt;br /&gt;ls: i_dont_exist: No such file or directory&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-116556619480106374?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/116556619480106374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=116556619480106374' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116556619480106374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116556619480106374'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/12/its-time-for-tee.html' title='Its time for tee'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-116125271455671826</id><published>2006-10-19T03:08:00.000-07:00</published><updated>2006-10-19T03:13:12.390-07:00</updated><title type='text'>Colorful Bash</title><content type='html'>Well here is how(er..i mean how not to :)) to make your terminal a bit more colorful&lt;br /&gt;&lt;code&gt;&lt;br /&gt;[kalyan@duck snippets]$PROMPT_COMMAND='tput setf $(( RANDOM % 7 + 1 ))'&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;And so we get a colorful terminal&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4580/1062/1600/snippets.png"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://photos1.blogger.com/blogger/4580/1062/320/snippets.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-116125271455671826?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/116125271455671826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=116125271455671826' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116125271455671826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/116125271455671826'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/10/colorful-bash.html' title='Colorful Bash'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-115286390686434212</id><published>2006-07-14T00:52:00.000-07:00</published><updated>2006-08-21T05:19:38.866-07:00</updated><title type='text'>Bash Meditation</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;p&gt;  &lt;/p&gt;  &lt;p&gt; Here is the oneliner for meditation in bash  &lt;/p&gt;  &lt;p&gt;  &lt;/p&gt;  &lt;code&gt; while :; do whoami; done &lt;/code&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-115286390686434212?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/115286390686434212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=115286390686434212' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/115286390686434212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/115286390686434212'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/07/bash-meditation.html' title='Bash Meditation'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114775292930425501</id><published>2006-05-15T21:10:00.000-07:00</published><updated>2006-05-31T10:04:06.523-07:00</updated><title type='text'>First post using Flock</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;Let me see :) &lt;br/&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114775292930425501?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114775292930425501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114775292930425501' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114775292930425501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114775292930425501'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/05/first-post-using-flock.html' title='First post using Flock'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114544027740420480</id><published>2006-04-19T02:45:00.000-07:00</published><updated>2006-05-12T11:53:38.300-07:00</updated><title type='text'>CSS Woes!!!</title><content type='html'>Well spent a good deal of time with Prateek debugging an issue with links not getting underlined &lt;br /&gt;when &amp;lt;a name=  is used and ended up with this&lt;br /&gt;&lt;br /&gt;&lt;a href="http://developer.mozilla.org/en/docs/Migrate_apps_from_Internet_Explorer_to_Mozilla#hover_differences"&gt;Migrate apps from Internet Explorer to Mozilla&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Thank you guys :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114544027740420480?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114544027740420480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114544027740420480' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114544027740420480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114544027740420480'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/04/css-woes.html' title='CSS Woes!!!'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114517660732277222</id><published>2006-04-16T01:27:00.000-07:00</published><updated>2006-04-16T02:42:18.626-07:00</updated><title type='text'>Bash : Order of expansions</title><content type='html'>This one is an important thing to understand for anyone who wants to know how bash works.&lt;br /&gt;So here is a refresher, this is the order of expansions:&lt;br /&gt;    * brace expansion&lt;br /&gt;    * tilde expansion&lt;br /&gt;    * parameter and variable expansion&lt;br /&gt;    * command substitution&lt;br /&gt;    * arithmetic expansion&lt;br /&gt;    * word splitting&lt;br /&gt;    * filename expansion&lt;br /&gt;Now here is what i am going to do,go through all of these and actually see if they work as they should.&lt;br /&gt;First lets check the first two : brace expansion and tilde expansion&lt;br /&gt;&lt;code&gt;kalyan@thunderbird:~$ echo ~ #tilde expansion:current users homedir&lt;br /&gt;/home/kalyan&lt;br /&gt;kalyan@thunderbird:~$ echo ~b  &lt;br /&gt;~b&lt;br /&gt;#tilde expansion fails: no user with name b&lt;br /&gt;kalyan@thunderbird:~$ echo ~kalyan &lt;br /&gt;/home/kalyan&lt;br /&gt;#tilde expansion works and gives kalyan user's home dir&lt;br /&gt;kalyan@thunderbird:~$ echo a{b,,c} #brace expansion&lt;br /&gt;ab a ac&lt;br /&gt;kalyan@thunderbird:~$ echo ~{b,,kalyan} #test to see who comes first&lt;br /&gt;~b /home/kalyan /home/kalyan&lt;br /&gt;kalyan@thunderbird:~$ echo /home/kalyan{b,,kalyan} &lt;br /&gt;/home/kalyanb /home/kalyan /home/kalyankalyan&lt;br /&gt;#brace expansion first as otherwise we'd get&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now time for parameter and variable expansion. This is simple to check we add a variable&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kalyan@thunderbird:~$ myvar=kalyan&lt;br /&gt;kalyan@thunderbird:~$ echo $myvar&lt;br /&gt;kalyan&lt;br /&gt;kalyan@thunderbird:~$ echo ~{b,,$myvar} &lt;br /&gt;~b /home/kalyan ~$myvar&lt;br /&gt;#strange, no variable expansion&lt;br /&gt;kalyan@thunderbird:~$ echo ~{b,,"$myvar"} &lt;br /&gt;~b /home/kalyan ~kalyan&lt;br /&gt;#variable expansion but only after tilde expansion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;So we need to enclose the variable in quotes to force bash to expand in this scenario.&lt;br /&gt;Okay lets move on to command substitution now&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kalyan@thunderbird:~$ cat &gt; myfile &lt;br /&gt;kalyan&lt;br /&gt;#create a file with contents as my name&lt;br /&gt;kalyan@thunderbird:~$ cat myfile #&lt;br /&gt;kalyan&lt;br /&gt;kalyan@thunderbird:~$ myvar1=myfile&lt;br /&gt;#create a variable with value myfile &lt;br /&gt;kalyan@thunderbird:~$ cat $myvar1&lt;br /&gt;kalyan&lt;br /&gt;kalyan@thunderbird:~$ echo $(cat $myvar1) &lt;br /&gt;kalyan&lt;br /&gt;#shows myvar1 is expanded before command substitution&lt;br /&gt;kalyan@thunderbird:~$ echo ~{b,,$(cat $myvar1)} &lt;br /&gt;~b /home/kalyan ~$(cat $myvar1)&lt;br /&gt;#so no var expansion or command substitution&lt;br /&gt;kalyan@thunderbird:~$ echo ~{b,,"$(cat $myvar1)"} &lt;br /&gt;~b /home/kalyan ~kalyan&lt;br /&gt;#we put quotes and now it works&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;So that proved that command substitution follows variable/parameter expansion. Now its arithmetic expansion&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kalyan@thunderbird:~$ echo $(( 5 + 5 )) #arithmetic expansion&lt;br /&gt;10&lt;br /&gt;kalyan@thunderbird:~$ cat &gt; five&lt;br /&gt;5&lt;br /&gt;kalyan@thunderbird:~$ cat five&lt;br /&gt;5&lt;br /&gt;kalyan@thunderbird:~$ echo $(( $(cat five) + $(cat five) )) &lt;br /&gt;10&lt;br /&gt;#we should get 10. :)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;That was neat. wasnt it :)..now time to get little insane. Bash splits words using the characters in IFS as the seperator so lets engineer an example to prove that word splitting happens after arithmetic expansion ;)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kalyan@thunderbird:~$ echo $(( 101010101 + 202020202  ))&lt;br /&gt;303030303&lt;br /&gt;kalyan@thunderbird:~$ OFS=$IFS #save the IFS&lt;br /&gt;kalyan@thunderbird:~$ IFS=3 #change it&lt;br /&gt;kalyan@thunderbird:~$ echo $(( 101010101 + 202020202  ))&lt;br /&gt; 0 0 0 0&lt;br /&gt;#wow where did the 3's go, they were removed during word splitting :)&lt;br /&gt;kalyan@thunderbird:~$ IFS=$OFS #back to sanity&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now we are onto the last expansion and thats filename expansion. bash actually looks for files to expand '*','?'.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kalyan@thunderbird:~/fun$ cat &gt; 10_file_name_starts_with_ten&lt;br /&gt;hmm i am tired of bash expansions now :)&lt;br /&gt;kalyan@thunderbird:~/fun$ echo 10*&lt;br /&gt;10_file_name_starts_with_ten&lt;br /&gt;kalyan@thunderbird:~/fun$ IFS=2 #for the example below&lt;br /&gt;kalyan@thunderbird:~/fun$ echo $(( 30*7 ))*&lt;br /&gt; 10_file_name_starts_with_ten&lt;br /&gt;#30*7 expands to 210 then bash removes '2' because of word splitting,that leaves us with 10* which undergoes filename expansion ..so simple :P&lt;br /&gt;kalyan@thunderbird:~/fun$ IFS=$OFS #restore sanity&lt;br /&gt;&lt;/code&gt; &lt;br /&gt;Thats it and i really mean it when i say &lt;code&gt; hmm i am tired of bash expansions now :)&lt;br /&gt; &lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114517660732277222?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114517660732277222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114517660732277222' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114517660732277222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114517660732277222'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/04/bash-order-of-expansions.html' title='Bash : Order of expansions'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114422635224345143</id><published>2006-04-05T01:37:00.000-07:00</published><updated>2007-02-15T20:04:14.396-08:00</updated><title type='text'>Why gmail sucks</title><content type='html'>Have a look at its Received Header in More Options , Show Original&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Received: by 10.70.90.15 with SMTP id n15csd722wxb;&lt;br /&gt;        Thu, 9 Mar 2006 00:46:04 -0800 (PST)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now why would I care for a stupid mail server's internal i.p?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114422635224345143?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114422635224345143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114422635224345143' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114422635224345143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114422635224345143'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/04/why-gmail-sucks.html' title='Why gmail sucks'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114421891465661085</id><published>2006-04-04T23:25:00.000-07:00</published><updated>2006-04-04T23:35:14.656-07:00</updated><title type='text'>Firefox  cookie policy</title><content type='html'>Firefox (1.5,1.0.7) lets you set a domain level cookies for top level domain for example ac.uk.&lt;br /&gt;IE blocks these cookies but firefox allows them,so which one is better ? :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114421891465661085?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114421891465661085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114421891465661085' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114421891465661085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114421891465661085'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/04/firefox-cookie-policy.html' title='Firefox  cookie policy'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114318840475005792</id><published>2006-03-24T00:11:00.000-08:00</published><updated>2006-03-24T23:25:33.513-08:00</updated><title type='text'>Key findings</title><content type='html'>Haven't blogged bash for a while but then BASH is good :)&lt;br /&gt;&lt;br /&gt;Problem: Application A has many config files ( only mutiple lines of key=value type), so one big config file is created merging all the ones(in a very randomized fashion). Now how do you verify that the merged configuration file has not missed out anything.&lt;br /&gt;&lt;br /&gt;Solution: A single line of bash code :)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;for i in small* ; do while read new; do grep -q ${new%=*} big.cfg || echo ${new%=*} of file $i not found in big.cfg ; done &lt; $i ;done &lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114318840475005792?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114318840475005792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114318840475005792' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114318840475005792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114318840475005792'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/03/key-findings.html' title='Key findings'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-114285818559892941</id><published>2006-03-20T04:29:00.000-08:00</published><updated>2006-03-20T04:43:35.140-08:00</updated><title type='text'>Formula One</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4580/1062/1600/zz.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4580/1062/320/zz.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Spent this weekend in KL (Kuala lumpur) with some friends from Thoughtworks ..Gabbar..Dator..S2m8kh..Little Chaman..Superman. Had great fun and in the process learnt a thing or two about F1..which I intend to unlearn soon :)...Dator looks crestfallen after Kimi's exit :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-114285818559892941?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/114285818559892941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=114285818559892941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114285818559892941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/114285818559892941'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2006/03/formula-one.html' title='Formula One'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112738346961382759</id><published>2005-09-22T03:01:00.000-07:00</published><updated>2005-09-22T03:04:29.620-07:00</updated><title type='text'>List assignment in scalar/boolean context in perl</title><content type='html'>Though this one is about perl but as i havent blogged for sometime&lt;br /&gt;I'll post it here.&lt;br /&gt;&lt;br /&gt;A collegue of mine was using a contruct like&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;while(my $temp = $sth-&gt;fetchrow_array)&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;{&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;# do work..&lt;/span&gt;&lt;br /&gt; &lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The problem was that whenever fetchrow_array returned 0 as&lt;br /&gt;the value ,the while would exit out.&lt;br /&gt;&lt;br /&gt;So the solution suggested by another colleague was to enclose $temp in a list&lt;br /&gt;such as &lt;span style="color: rgb(0, 0, 153);"&gt;(my $temp)=$sth-&gt;fetchrow_array&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;I was intrigued by this as a list should return the last element in scalar&lt;br /&gt;context.&lt;br /&gt;&lt;br /&gt;As it turns out&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;while((0))&lt;/span&gt; wouldnt enter the while block but strangely.&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;while(($temp)=(0))&lt;/span&gt; works.&lt;br /&gt;&lt;br /&gt;This is because a list assignment in scalar context returns the number of&lt;br /&gt;elements on the r.h.s of the assignment.&lt;br /&gt;&lt;br /&gt;Yup there is more than one way to do it and one could also use&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;while(defined($temp=(0)))&lt;/span&gt; ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112738346961382759?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112738346961382759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112738346961382759' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112738346961382759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112738346961382759'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/09/list-assignment-in-scalarboolean.html' title='List assignment in scalar/boolean context in perl'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112426589585236745</id><published>2005-08-17T01:01:00.000-07:00</published><updated>2005-08-17T01:04:55.860-07:00</updated><title type='text'>Removing newlines from a file using sed</title><content type='html'>I kept forgetting this as I never really realized that sed is a line editor.&lt;br /&gt;So the newline at the end of the line isnt available by default unless we create a multiline pattern space using N.&lt;br /&gt;&lt;br /&gt;Anyways here is the sed command that does the magic.&lt;br /&gt; &lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$sed ':a;N;$!ba;s/\n//g' filename&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Among other things it uses labels and N command. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112426589585236745?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112426589585236745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112426589585236745' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112426589585236745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112426589585236745'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/removing-newlines-from-file-using-sed.html' title='Removing newlines from a file using sed'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112383969878466349</id><published>2005-08-12T02:24:00.000-07:00</published><updated>2007-02-15T03:29:27.366-08:00</updated><title type='text'>Python regex to match a floating point number</title><content type='html'>Here is the expression to match a float upto two places of decimal.&lt;br /&gt;((?&amp;lt;\.|\d)\d+ (?:\.\d{1,2})?)So let me explain it in steps:&lt;br /&gt;&lt;br /&gt;'(?&amp;lt;!..)' is a negative look behind,i.e,at that position the preceding text should not match the regex enclosed in '(?&amp;lt;! )'.In this case it is '\.|\d' which stands for a literal dot or a digit.This is not part of the match,the regex that needs to match starts with '\d+'.&lt;br /&gt;So what we are saying is match 1 or more digits but make sure those digits are not preceded by a literal dot or a digit. Well one can understand why digits shouldnot be preceded by a literal '.' (dot) ,for example we dont want .99 to match but why do we need the digit part. The reason is quite subtle but without it .99 will be matched by the regex.&lt;br /&gt;&lt;br /&gt;This is because when regex engine will try to match .99 initially it will fail \d+ matches 99 but as it is preceded by negative lookbehind for a literal '.',the match cant succeed so the engines shifts to next character and makes \d+ match only the rightmost 9 in 99.&lt;br /&gt;Also as the rightmost 9 is preceded by a 9 the negative look behind is also satisfied so \d+ will be end up matching just the 9.&lt;br /&gt;This is a false positive as we definitely dont want to match that so we make the negative look behind include a digit to rule out this result&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112383969878466349?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112383969878466349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112383969878466349' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112383969878466349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112383969878466349'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/python-regex-to-match-floating-point.html' title='Python regex to match a floating point number'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112383866127180132</id><published>2005-08-12T02:22:00.000-07:00</published><updated>2005-08-12T02:24:21.276-07:00</updated><title type='text'>Bash arrays</title><content type='html'>First off inside bash arrays ,elements are separated by space.&lt;br /&gt;Have a look at this.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$cat new.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;length=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;positions=(0 1 2)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;positions[length+1]=4&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo "${positions[*]}"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;./new.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;0 1 4&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Point to note is that 'length' as well as '$length' areboth valid indexes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112383866127180132?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112383866127180132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112383866127180132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112383866127180132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112383866127180132'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/bash-arrays.html' title='Bash arrays'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112375422790008502</id><published>2005-08-11T02:41:00.000-07:00</published><updated>2005-08-11T02:59:47.616-07:00</updated><title type='text'>bre,ere and pcre</title><content type='html'>Its been a while since I had a look at "Mastering Regular Expressions" by Jeff Friedl but I am glad i went through it once.&lt;br /&gt;&lt;br /&gt;So the input is like&lt;br /&gt;&lt;br /&gt;filename="http://really.big.url/test?foo=bar"&lt;br /&gt;&lt;br /&gt;So my first attempt at extracting  the url was&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$cat output| sed   's/^.*filename=//'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So someone pointed out that the url could contain 'filename=',yeah thats quite possible and proposed a solution with back-references as sed doesnt have non greedy quantifiers which are common to pcre(perl compatible regular expressions).Sed only supports bre(basic regular expressions) and ere(extended regular expression).Dont ask me what they are :).&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;br /&gt;$cat output| sed -r 's/^[[:space:]]*filename="([^"]*)"[[:space:]]*$/\1/g&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In addition to making space for "spaces" :),this moves the greedy "*" to the left hand side of "filename=" so that any extra "filename=" are matched by the greedy "*".&lt;br /&gt;&lt;br /&gt;The same thing in perl could be simply done by&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$cat output|perl -wpe 's/^.*?filename=//;'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112375422790008502?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112375422790008502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112375422790008502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112375422790008502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112375422790008502'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/breere-and-pcre.html' title='bre,ere and pcre'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112368381506752304</id><published>2005-08-10T07:18:00.000-07:00</published><updated>2005-08-10T07:23:35.073-07:00</updated><title type='text'>Limits of sed</title><content type='html'>Well a user had a huge ascii file 1.5 gigs and all of that on a single line.Wow!&lt;br /&gt;&lt;br /&gt;So the job was to make it a span many lines,by putting a newline after every 310 characters.&lt;br /&gt;&lt;br /&gt;So the suggested sed expression was:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$sed 's/\(.\{310\}\)/\1\n/'  filename&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;But it appears that sed crapped out with following error:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;sed: Couldn't re-allocate memory&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Maybe something like C is better suited for this as sed is basically a line editor,so maybe tries to read and operate on it in a single go :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112368381506752304?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112368381506752304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112368381506752304' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112368381506752304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112368381506752304'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/limits-of-sed.html' title='Limits of sed'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112366634336952352</id><published>2005-08-10T02:27:00.000-07:00</published><updated>2005-08-10T02:32:23.376-07:00</updated><title type='text'>A bit of sed and awk magic</title><content type='html'>The task is to find the total cpu utilization of httpd processes.&lt;br /&gt;Instead of doing all kinds of acrobatics with grep,bc and bash loops , one can simply use awk.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ps aux | awk '/httpd/{s+=$3}END{print s}'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;One a side note , gnu sed can change a file in-place .This is done by using the "i" option.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$sed -i 's/fun/bun/' test.txt&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112366634336952352?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112366634336952352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112366634336952352' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112366634336952352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112366634336952352'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/bit-of-sed-and-awk-magic.html' title='A bit of sed and awk magic'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112314689333691202</id><published>2005-08-04T02:11:00.000-07:00</published><updated>2005-08-04T02:14:53.343-07:00</updated><title type='text'>Disable enter key in bash</title><content type='html'>Well this is very straightforward, we just need to unbind keybinding for&lt;br /&gt;"\r".Thats easily done using bind.&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 153);"&gt;bind -r '\r'&lt;/pre&gt;&lt;br /&gt;Now to get the binding back i used.&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 153);"&gt;bind '"\r":accept-line'&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt; Obviously i had to hit Ctrl-J instead of "Enter" :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112314689333691202?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112314689333691202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112314689333691202' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112314689333691202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112314689333691202'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/08/disable-enter-key-in-bash.html' title='Disable enter key in bash'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112255812918986247</id><published>2005-07-28T06:29:00.000-07:00</published><updated>2005-07-28T06:48:28.186-07:00</updated><title type='text'>Ctrl-XCtrl-V</title><content type='html'>Well i just bumped into this article (&lt;a href="http://www.chiark.greenend.org.uk/%7Esgtatham/bash-notify/"&gt;http://www.chiark.greenend.org.uk/~sgtatham/bash-notify/&lt;/a&gt;)&lt;br /&gt;searching for aynchronous jobs.&lt;br /&gt;As my  brain is a non starter i dont understand some terms like asynchronous.&lt;br /&gt;So now to keep things simple i feel an asynchronous job is a background job as it can end anytime :).&lt;br /&gt;&lt;br /&gt;According to the article "set -b" and "set +b" both of them have issues.&lt;br /&gt;set -b will just corrupt your display and "set +b" can create lot of jobs.Dont ask me why :).&lt;br /&gt;But the feature of Ctrl-XCtrl-V prints the bash version etc and then restores the command line on new line "as it was".&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ps ax&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;GNU bash, version 3.00.16(1)-release (i686-pc-linux-gnu)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ps ax&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The author had even written a patch for this ..Will have a look at it sometime :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112255812918986247?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112255812918986247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112255812918986247' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112255812918986247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112255812918986247'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/ctrl-xctrl-v.html' title='Ctrl-XCtrl-V'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112254673157631765</id><published>2005-07-28T03:29:00.000-07:00</published><updated>2005-07-28T03:32:11.583-07:00</updated><title type='text'>hash builtin - 2</title><content type='html'>Okay i am back to the hash builtin again.Lets trace phash_flush in hashcmd.c.&lt;br /&gt;As expected it calls hash_flush.A look at the top of the function shows what it does,removes and discards&lt;br /&gt;all entries in TABLE.If FREE_DATA is non-null then its kind of a destructor else call free() to free up the memory.&lt;br /&gt;&lt;br /&gt;First it is checked if (table == 0) or if number of entries  in the table are zero.&lt;br /&gt;&lt;br /&gt;Once we are sure that number of hash entries are not zero, we iterate through the hash tables buckets.&lt;br /&gt;Typically we call free(item-&gt;data),free(item-&gt;key) and free(item).&lt;br /&gt;&lt;br /&gt;And finally we set the initial bucket pointer to NULL and set the number of entries to zero.&lt;br /&gt;&lt;br /&gt;This is quite staightforward ,the way it should be.&lt;br /&gt;So as we are doing okay ,lets move to the other functions.&lt;br /&gt;Lets see phash_remove now,this as expected calls hash_remove.&lt;br /&gt;A peek inside the code shows we try to get the bucket for the string first.&lt;br /&gt;This buckets is got by hashing the string and anding with number of buckets -1 :).&lt;br /&gt;The string typically is 'ls','ps' etc no mention of the data here but then who cares when its is getting deleted.&lt;br /&gt;No.The pointer is being returned after being deleted from the list so lets go back to phash_remove.&lt;br /&gt;Well i went back to phash_remove and tried to print the data before it gets freed.No luck.&lt;br /&gt;I am reading junk so where is the path stored??&lt;br /&gt;Okay i screwed up again ,without reading i assumed the complete file path would be stored as item-&gt;data but&lt;br /&gt;thats not the case.item-&gt;data is a pointer to a struct PATH_DATA which contains the path.&lt;br /&gt;&lt;br /&gt;Didnt i tell you my brain is a goner anyway back to code and let me print the pathname just before it gets freed,&lt;br /&gt;(Dead Man Walking style) :).&lt;br /&gt;&lt;br /&gt;Bingo.. now i get to print /usr/bin/ls just before its cleaned up by "hash -d ls" :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112254673157631765?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112254673157631765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112254673157631765' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112254673157631765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112254673157631765'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/hash-builtin-2.html' title='hash builtin - 2'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112247102781343631</id><published>2005-07-27T06:28:00.000-07:00</published><updated>2005-07-27T06:30:27.820-07:00</updated><title type='text'>hash builtin</title><content type='html'>I think my brain will finally be a non starter.Anyhow here are my thoughts on the hash builtin of bash.&lt;br /&gt;&lt;br /&gt;So i browsed haslib.h where &lt;span style="color: rgb(0, 0, 153);"&gt;HASH_TABLE &lt;/span&gt;is defined as&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;typedef struct hash_table {&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  BUCKET_CONTENTS **bucket_array;    /* Where the data is kept. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  int nbuckets;            /* How many buckets does this table have. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  int nentries;            /* How many entries does this table have. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Obviously the next question would be what is BUCKET_CONTENTS,remember a hash has buckets..&lt;br /&gt;Well not quite..:) anyways as we have the source with us lets go there ..:)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;typedef struct bucket_contents {&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  struct bucket_contents *next;    /* Link to next hashed key in this bucket. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  char *key;            /* What we look up. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  PTR_T data;            /* What we really want. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  unsigned int khash;        /* What key hashes to */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;  int times_found;        /* Number of times this item has been found. */&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;} BUCKET_CONTENTS;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As we can see hash_table has bucket_array,number of buckets and number of entries.&lt;br /&gt;I have feeling the number of buckets may increase as we need more...&lt;br /&gt;As we look into BUCKET_CONTENTS has a pointer to the next bucket,&lt;br /&gt;a key ( like 'ls'),data (/usr/bin/ls),khash ( i think this is the hashed value),&lt;br /&gt;times_found ( lol..source is enough i guess :) ).&lt;br /&gt;&lt;br /&gt;Now lets look at the functions in hashcmd.c&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;phash_create&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;phash_freedata&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;phash_flush&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;phash_insert&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;phash_insert&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;phash_search&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;phash_create&lt;br /&gt;This in turn calls hash_create (hashlib.c) with appropriate number of buckets (&lt;span style="color: rgb(0, 0, 153);"&gt;FILENAME_HASH_BUCKETS=64&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;phash_search&lt;br /&gt;Probably this is what is interesting,this in turn ccalls hash_search.&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;bucket= HASH_BUCKET(string,table,hv)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;this in turns calls hash_string,the real hashing function.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;for (i = 0; *s; s++)&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;    {&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;      i *= 16777619;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;      i ^= *s;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The comment says magic is in the interesting relationship between the special prime 16777619 and 2^32 and 2^8.&lt;br /&gt;As fas as i can tell,2^8 is *s and i is 2^32 :).&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;HASH_BUCKET&lt;/span&gt; ands the value of string with the number of buckets.&lt;br /&gt;I am just thinking of collisions but i guess each bucketjust starts up a link list.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112247102781343631?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112247102781343631/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112247102781343631' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112247102781343631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112247102781343631'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/hash-builtin.html' title='hash builtin'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112246070732602587</id><published>2005-07-27T03:36:00.000-07:00</published><updated>2005-07-27T03:38:27.333-07:00</updated><title type='text'>spawnve</title><content type='html'>There was this patch on the bash mailing about making bash run faster on cygwin.&lt;br /&gt;&lt;br /&gt;It was pointed out that there were issues with signal handling after the patch is applied.&lt;br /&gt;After the function in the patch is called SIGINT handler is getting lost making the shell to exit instead of just cancelling the current line.&lt;br /&gt;&lt;br /&gt;A quick look at the patch shows the following code.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;+  sigdelset(&amp;child_sig_mask, SIGTSTP);&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;+  sigdelset(&amp;child_sig_mask, SIGTTIN);&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;+  sigdelset(&amp;child_sig_mask, SIGTTOU);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Job control signals are removed from the child_sig_mask,so does that mean they will not be blocked?&lt;br /&gt;In any case the mask was set to top_level_mask instead of child_sig_mask in the following line and was pointed out.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;+ sigprocmask (SIG_SETMASK, &amp;top_level_mask, &amp;amp;old_sig_mask);&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112246070732602587?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112246070732602587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112246070732602587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112246070732602587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112246070732602587'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/spawnve.html' title='spawnve'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112202993855807291</id><published>2005-07-22T03:54:00.000-07:00</published><updated>2005-07-22T03:58:58.570-07:00</updated><title type='text'>Quoting during command substitution</title><content type='html'>I was corrected in #bash channel in irc by trash regarding this.&lt;br /&gt;&lt;br /&gt;During variable assignment,its better to quote the rhs.&lt;br /&gt;&lt;br /&gt;For example&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 153);"&gt;$myvar="hello world"&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;but this isnt needed if you are doing something like&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 153);"&gt;$myvar="$(echo hello world)"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As this is equivalent to&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 153);"&gt;$myvar=$(echo hello world)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112202993855807291?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112202993855807291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112202993855807291' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112202993855807291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112202993855807291'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/quoting-during-command-substitution.html' title='Quoting during command substitution'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112133722271814391</id><published>2005-07-14T03:29:00.000-07:00</published><updated>2005-07-14T03:34:24.310-07:00</updated><title type='text'>A small thing about vi regex</title><content type='html'>Well i was trying to remove all the spaces in the lines that are present before text.&lt;br /&gt;&lt;br /&gt;So i thought to use vi's command mode and run&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;:%s/^\s+//&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But this doesnt work ,then i found out (http://www.geocities.com/volontir/) that in vi the way to specify the '+' quantifier is to use,&lt;br /&gt;'\+'.So it turns out the way to do it is .&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;:%s/^\s\+//&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Also '?' quantifier is '\='.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112133722271814391?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112133722271814391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112133722271814391' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112133722271814391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112133722271814391'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/small-thing-about-vi-regex.html' title='A small thing about vi regex'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112108788393835986</id><published>2005-07-11T06:15:00.000-07:00</published><updated>2005-07-11T07:25:04.736-07:00</updated><title type='text'>PROMPT_COMMAND</title><content type='html'>Its an interesting bash variable..bash whenever it finishes a command or null command would try to run this..&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ PROMPT_COMMAND=date&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Mon Jul 11 18:46:42 IST 2005&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Mon Jul 11 18:46:42 IST 2005&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Mon Jul 11 18:46:43 IST 2005&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Mon Jul 11 18:46:43 IST 2005&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ uname&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Linux&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Mon Jul 11 18:47:23 IST 2005&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I guess it will be more fun to set it to "clear" :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112108788393835986?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112108788393835986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112108788393835986' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112108788393835986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112108788393835986'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/promptcommand.html' title='PROMPT_COMMAND'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112107584721979595</id><published>2005-07-11T02:46:00.000-07:00</published><updated>2005-07-11T02:57:27.226-07:00</updated><title type='text'>completion for directories starting with '='</title><content type='html'>Initially i thought this could be a bug but later realised that this behavior is because of readline treating '=' as a word break character.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;# mkdir =foo =foobar&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;# cd =\=foo&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;-bash: cd: ==foo: No such file or directory&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Basically when you hit TAB after types just '=' , bash adds "\=foo".&lt;br /&gt;&lt;/pre&gt;What is treated as a word break character can be modified by changing the value of COMP_WORDBREAKS(Thanks to Chet :) ).&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ echo $COMP_WORDBREAKS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;"'@&gt;&lt;=;|&amp;(: &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ echo $COMP_WORDBREAKS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;"'@&gt;&lt;;|&amp;amp;(:&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Also you just saw bash's search and replace functionality.If there is no "slash" in the end ,the pattern is deleted from the variable :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112107584721979595?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112107584721979595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112107584721979595' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112107584721979595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112107584721979595'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/completion-for-directories-starting.html' title='completion for directories starting with &apos;=&apos;'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112063394424968170</id><published>2005-07-06T00:03:00.000-07:00</published><updated>2005-07-06T00:13:43.676-07:00</updated><title type='text'>filename expansion after parameter expansion</title><content type='html'>This point came up during an intersting post on bug-bash.I just ran a few commands to check this out.&lt;br /&gt;&lt;br /&gt;If nullgob is set then bash will not echo the pattern if it fails the filename expansion.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$echo abc*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;abc*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$shopt -s nullglob&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$echo abc*&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;So now if you have a variable like&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$test=p*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$echo $test&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;purchase&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$echo "$test"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;*&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Moral of the story:Quoting (double) a variable suppresses filename expansion.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112063394424968170?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112063394424968170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112063394424968170' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112063394424968170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112063394424968170'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/filename-expansion-after-parameter.html' title='filename expansion after parameter expansion'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-112045463646498538</id><published>2005-07-03T22:21:00.000-07:00</published><updated>2005-07-05T05:30:10.900-07:00</updated><title type='text'>Three arrows</title><content type='html'>&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ cat &lt;&lt;&lt; Yothere&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Yothere&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;cat &lt;&lt;&lt; "$(&lt; for.sh)"&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#for(( i=1;i&lt;6;i++))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;for i in $(ls)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo $i&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;done&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I can call it extended here document .So as you can see this allows for variable subsitution as well. :)&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-112045463646498538?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/112045463646498538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=112045463646498538' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112045463646498538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/112045463646498538'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/07/three-arrows.html' title='Three arrows'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111959446620666744</id><published>2005-06-23T23:24:00.000-07:00</published><updated>2005-07-03T22:20:28.523-07:00</updated><title type='text'>Mama i am coming home..</title><content type='html'>Some times mama maynot be back home to receive you ,in that case you become a zombie .Mama need to call wait to make sure all the kids are back.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;%cat checkzombie.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;./zombie1 &amp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;./zombie&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;wait&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;%cat zombie1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;sleep 60&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;%cat zombie&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;sleep 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you dont call wait at the end,the script will return before zombie1 is done as&lt;br /&gt;zombie was executed as a background job.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111959446620666744?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111959446620666744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111959446620666744' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111959446620666744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111959446620666744'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/mama-i-am-coming-home.html' title='Mama i am coming home..'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111951841202890506</id><published>2005-06-23T02:17:00.000-07:00</published><updated>2005-06-23T02:20:12.033-07:00</updated><title type='text'>Job Control</title><content type='html'>Job control lets you suspend _lot of jobs and then bring them into foreground.&lt;br /&gt;Ctrl-Z takes the job into background...&lt;br /&gt;But you can get it back by 'fg %n' where n is the ID of the job.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ jobs&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;[1]-  Stopped                 ./trace.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;[2]+  Stopped                 ./trace.sh&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$ fg %2&lt;/span&gt;&lt;br /&gt; Coming soon are the traps in bash..beware..:)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111951841202890506?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111951841202890506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111951841202890506' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111951841202890506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111951841202890506'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/job-control.html' title='Job Control'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111950985601242413</id><published>2005-06-22T23:53:00.000-07:00</published><updated>2005-06-23T00:03:18.440-07:00</updated><title type='text'>A text browser with links --dump</title><content type='html'>This browser implemets quit (q) , back (b) and url.And a hidden command called 'd' which dumps history.More importantly i use the bash arrays.On L.H.S its HISTORY[$i] where as on R.H.S its ${HISTORY[$i]} and the length of array is ${#HISTORY[@]}...&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;HISTORY=()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;BACKINDEX=0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;function updatehistory() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    numvalues=${#HISTORY[@]}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    if (( $numvalues &lt; 3 ))&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            HISTORY[$numvalues]=$1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    index=$(( numvalues -1))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            for (( i=0;i&lt;$index;i++))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                         j=$(( i+1))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                     HISTORY[$i]=${HISTORY[$j]}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    done&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    i=$(( i++))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                HISTORY[$i]=$1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            fi&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;function dump_history(){&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;numvalues=${#HISTORY[@]}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        for (( i=0; i &lt; $numvalues; i++))&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    echo ${HISTORY[$i]}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        done&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;while true&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        echo "Enter a url.q for quit and b for back"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        read choice&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        case $choice in&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            q) exit ;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            b) BACKINDEX=$(( BACKINDEX+1))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            numvalues=${#HISTORY[@]}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;              INDEX=$(( numvalues - BACKINDEX -1 ))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;              links  -http-proxy proxyserver:8088  -dump ${HISTORY[$INDEX]}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;              ;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            d) dump_history;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            *) links  -http-proxy proxyserver:8088  -dump $choice&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                        if ((  $? == 0 ))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    updatehistory $choice&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                        fi&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                        BACKINDEX=0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                        ;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        esac&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;done&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111950985601242413?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111950985601242413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111950985601242413' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111950985601242413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111950985601242413'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/text-browser-with-links-dump.html' title='A text browser with links --dump'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111943624919363740</id><published>2005-06-22T03:28:00.000-07:00</published><updated>2005-06-22T03:32:01.166-07:00</updated><title type='text'>Counting lines with grep</title><content type='html'>Interesting option called -c , which lets you suppress output and oonly print the count of lines that matched so here is a replacement for "wc -l".&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;%cat bajajautofinance |grep -c  ^.*$&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;11&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;%cat bajajautofinance |wc -l&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;11&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111943624919363740?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111943624919363740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111943624919363740' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111943624919363740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111943624919363740'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/counting-lines-with-grep.html' title='Counting lines with grep'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111935270740727717</id><published>2005-06-21T02:42:00.000-07:00</published><updated>2005-06-21T04:21:38.476-07:00</updated><title type='text'>A menu based bash directory browser</title><content type='html'>This could be useful when you have long pathnames to browse around and these pathnames have similar names...so CDPATH may not work.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;function cd()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;if [ -z "$1" ]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    pushd $HOME&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    return 0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;fi&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;THEDIR=$(echo $1|sed -e "s/\~/$(echo $HOME|sed -e 's/\//\\\//g')/g")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;pushd $THEDIR &gt;/dev/null 2&gt;&amp;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;function lsd()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;if [ -z "$1" ]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    select mydir in $(dirs -v|awk '{print $2}'|sort -u)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        cd $mydir&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        break&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        done&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        if [ -d "$1" ]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            select mydir in $(find $1 -type d)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    cd $mydir&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                    break&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        done&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    fi&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;fi&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111935270740727717?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111935270740727717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111935270740727717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111935270740727717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111935270740727717'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/menu-based-bash-directory-browser.html' title='A menu based bash directory browser'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111899218145843465</id><published>2005-06-17T00:07:00.000-07:00</published><updated>2005-06-17T00:09:59.966-07:00</updated><title type='text'>Blocks and IO</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo "Hello World"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo "Bye World"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;} &gt; output.txt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And here is some bad news..Daniel Robbins(Gentoo Founder) joins MS...isn't that cheap ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111899218145843465?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111899218145843465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111899218145843465' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111899218145843465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111899218145843465'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/blocks-and-io.html' title='Blocks and IO'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111872371307640821</id><published>2005-06-13T21:32:00.000-07:00</published><updated>2005-06-13T21:35:13.080-07:00</updated><title type='text'>Basic usage of select</title><content type='html'>Select creates a menu for you and its very simple to use.Here is an example&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#cat select.sh                &lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;select test&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;do&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;echo $test&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;done&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;#./select.sh item1 item2 item3&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;1) item1&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;2) item2&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;3) item3&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;#? 2&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;item2&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;1) item1&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;2) item2&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;3) item3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Also this creates an infinite loop...so you need a break :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111872371307640821?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111872371307640821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111872371307640821' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111872371307640821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111872371307640821'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/basic-usage-of-select.html' title='Basic usage of select'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111841271722657251</id><published>2005-06-10T06:41:00.000-07:00</published><updated>2005-06-10T07:11:57.230-07:00</updated><title type='text'>Using eval</title><content type='html'>Here is some recursive(?) cool usage of eval.Thanks to Chandra..&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$p=i&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$i=1&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$CM1=World&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$CM=Hello&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$eval HOST=\$CM\$$p&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$echo $HOST&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;Hello1&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$eval HOST=$CM\$CM$i&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$echo $HOST&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;HelloWorld&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$eval HOST=\$CM$i&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$echo $HOST&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;World&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111841271722657251?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111841271722657251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111841271722657251' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111841271722657251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111841271722657251'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/using-eval.html' title='Using eval'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111839799149405569</id><published>2005-06-10T03:05:00.000-07:00</published><updated>2005-06-10T03:10:49.903-07:00</updated><title type='text'>Bash string operators</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;while read foo&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo ${foo%%:*}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;case  ${foo%%:*} in&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;cm1*) export CM1=${foo##*:};;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;esac&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;done &lt; config.txt&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo $CM1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And the config.txt has syntax like&lt;br /&gt;tunnel_port : 9999&lt;br /&gt;&lt;br /&gt;Enjoy :)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111839799149405569?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111839799149405569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111839799149405569' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111839799149405569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111839799149405569'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/bash-string-operators.html' title='Bash string operators'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111813899704538452</id><published>2005-06-07T03:08:00.000-07:00</published><updated>2005-06-07T03:11:25.473-07:00</updated><title type='text'>Alternative for loop syntax</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:100%;" &gt;for(( i=1;i&lt;6;i++))&lt;br /&gt;do&lt;br /&gt;echo $i&lt;br /&gt;done&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111813899704538452?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111813899704538452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111813899704538452' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111813899704538452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111813899704538452'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/06/alternative-for-loop-syntax.html' title='Alternative for loop syntax'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111760341437907816</id><published>2005-05-31T22:18:00.000-07:00</published><updated>2005-06-01T07:04:34.216-07:00</updated><title type='text'>bash version of colorise python script</title><content type='html'>Well not exactly it only does a word not a string but i guess you get the idea.&lt;br /&gt;Here is the python version.&lt;br /&gt;&lt;span class="down" style="display: block;" id="formatbar_CreateLink" title="Link" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);"&gt;&lt;/span&gt;&lt;a href="http://vedanta.freecoolsite.com/comments.php?y=05&amp;m=05&amp;amp;entry=entry050531-070319"&gt;script in python&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;col=""&lt;br /&gt;function colorize {&lt;br /&gt;            case "$1" in   &lt;br /&gt;                "red" )&lt;br /&gt;                                   col=1;;&lt;br /&gt;                    "green" )&lt;br /&gt;                                   col=2;;&lt;br /&gt;               "yellow" )&lt;br /&gt;                                  col=3;;&lt;br /&gt;                   "blue" )&lt;br /&gt;                               col=4;;&lt;br /&gt;                     * )&lt;br /&gt;                          echo "wrong color dude"&lt;br /&gt;                          exit;;&lt;br /&gt;          esac&lt;br /&gt;&lt;br /&gt;returnstring="\033[;3${col}m${2}\033[0m"&lt;br /&gt;echo -e  $returnstring&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;strings=($*)&lt;br /&gt;&lt;br /&gt;for(( i=1;i&lt;$#;i++))&lt;br /&gt;do&lt;br /&gt;colorize $1 ${strings[$i]}&lt;br /&gt;echo -en " "&lt;br /&gt;done&lt;br /&gt;echo&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111760341437907816?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111760341437907816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111760341437907816' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111760341437907816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111760341437907816'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/bash-version-of-colorise-python-script.html' title='bash version of colorise python script'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111754649981568553</id><published>2005-05-31T06:32:00.000-07:00</published><updated>2005-05-31T06:34:59.816-07:00</updated><title type='text'>Searching forward through history</title><content type='html'>Well the key to do is ctrl-s but thats already bound to stop for the tty.&lt;br /&gt;So we undef that and use it :).&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$cat .bash_profile |grep stty&lt;br /&gt;stty stop undef start undef&lt;br /&gt;    (We press ctrl-s )&lt;br /&gt;(i-search)`':&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111754649981568553?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111754649981568553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111754649981568553' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111754649981568553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111754649981568553'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/searching-forward-through-history.html' title='Searching forward through history'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111754625978695702</id><published>2005-05-31T06:29:00.000-07:00</published><updated>2005-05-31T06:30:59.790-07:00</updated><title type='text'>Substitution in the previous command</title><content type='html'>Thanks to nujoom,there is one more bash trick.Only thing it works for the immediately previous command.The following sequence would end up opening the file in 'vi'.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$ls bajajautofinance&lt;br /&gt;bajajautofinance&lt;br /&gt;$^ls^vi&lt;br /&gt;vi bajajautofinance&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111754625978695702?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111754625978695702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111754625978695702' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111754625978695702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111754625978695702'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/substitution-in-previous-command.html' title='Substitution in the previous command'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111744059876576589</id><published>2005-05-29T23:29:00.000-07:00</published><updated>2005-05-30T01:09:58.773-07:00</updated><title type='text'>shopts</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#shopt -s cdable_vars&lt;br /&gt;#fd=/home/kalyan/fun/bash/&lt;br /&gt;#cd fd&lt;br /&gt;/home/kalyan/fun/bash/&lt;br /&gt;#pwd&lt;br /&gt;/home/kalyan/fun/bash&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111744059876576589?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111744059876576589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111744059876576589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111744059876576589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111744059876576589'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/shopts.html' title='shopts'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111743358627573410</id><published>2005-05-29T23:06:00.000-07:00</published><updated>2005-05-29T23:13:06.280-07:00</updated><title type='text'>Learning the Bash shell</title><content type='html'>Got my hands on the third edition of this book...&lt;br /&gt;Really good.&lt;br /&gt;So for sometime my glob would include stuff i try out reading this book..&lt;br /&gt;&lt;br /&gt;So here is something on aliases and options (set -o)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$set -o ignoreeof&lt;br /&gt;'if you type ctrl-d now'&lt;br /&gt;$Use "logout" to leave the shell.&lt;br /&gt;$set -o noclobber&lt;br /&gt;$echo hi &gt; temp.txt&lt;br /&gt;$cat temp.txt&lt;br /&gt;hi&lt;br /&gt;$echo sddsshi &gt; temp.txt&lt;br /&gt;-bash: temp.txt: cannot overwrite existing file&lt;br /&gt;$echo sddsshi &gt; temp.txt&lt;br /&gt;-bash: temp.txt: cannot overwrite existing file&lt;br /&gt;$echo sddsshi &gt; temp.txt&lt;br /&gt;-bash: temp.txt: cannot overwrite existing file&lt;br /&gt;$rm temp.txt&lt;br /&gt;$set -o noglob&lt;br /&gt;$ls *&lt;br /&gt;ls: *: No such file or directory&lt;br /&gt;$set -o ignoreeof&lt;br /&gt;$set -o nounset&lt;br /&gt;$ls $ASD&lt;br /&gt;-bash: ASD: unbound variable&lt;br /&gt;$cd mybash&lt;br /&gt;-bash: cd: mybash: No such file or directory&lt;br /&gt;$alias&lt;br /&gt;alias links='links -http-proxy rio:8088'&lt;br /&gt;$alias mybash=/home/kalyan/fun/bash/&lt;br /&gt;$cd mybash&lt;br /&gt;-bash: cd: mybash: No such file or directory&lt;br /&gt;$alias cd='cd '&lt;br /&gt;$cd mybash&lt;br /&gt;$pwd&lt;br /&gt;/home/kalyan/fun/bash&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111743358627573410?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111743358627573410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111743358627573410' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111743358627573410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111743358627573410'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/learning-bash-shell.html' title='Learning the Bash shell'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111719603770441847</id><published>2005-05-27T05:13:00.000-07:00</published><updated>2005-05-27T05:13:57.706-07:00</updated><title type='text'>Routing for localhost</title><content type='html'>Cant believe it but needed this to be done to ping localhost on vmware ...O o O&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;&lt;br /&gt;# ip route add 127.0.0.0/8 dev lo&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111719603770441847?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111719603770441847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111719603770441847' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111719603770441847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111719603770441847'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/routing-for-localhost.html' title='Routing for localhost'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111712334022601212</id><published>2005-05-26T08:57:00.000-07:00</published><updated>2005-05-26T09:02:20.230-07:00</updated><title type='text'>A thing about sed regex</title><content type='html'>Okay so on the left side you need to escape things like "(" "?" which are needed for example:&lt;br /&gt;&lt;br /&gt;To remove - from -bash from ps axo command listing ,i needed to do this.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#ps axo command|sed -ne "1d;s/^-\(.*\)/\1/p"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;And to make that thing optional,dont ask me why i did that ..yeah so to print all commands and to remove - from -bash when encountered.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#ps axo command|sed -ne "1d;s/^-\?\(.*\)/\1/p"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111712334022601212?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111712334022601212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111712334022601212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111712334022601212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111712334022601212'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/thing-about-sed-regex.html' title='A thing about sed regex'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111712110556185142</id><published>2005-05-26T08:16:00.000-07:00</published><updated>2005-05-26T08:25:05.566-07:00</updated><title type='text'>command command</title><content type='html'># ls &lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;awk&lt;/span&gt;  &lt;span style="color: rgb(0, 153, 0);"&gt;complete2.sh  complete.sh&lt;/span&gt;  &lt;span style="color: rgb(0, 0, 153);"&gt;downloads  medrec-1.1&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;  ps.sh  rmmod.sh  test.sh  url.sh&lt;/span&gt;&lt;br /&gt;# command ls&lt;br /&gt;awk  complete2.sh  complete.sh downloads  medrec-1.1  ps.sh  rmmod.sh   test.sh  url.sh&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now command executes a command yeah "  Run  command  with  args  suppressing  the normal shell function lookup"&lt;br /&gt;&lt;br /&gt;So my deduction is color gotta be a shell function ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111712110556185142?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111712110556185142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111712110556185142' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111712110556185142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111712110556185142'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/command-command.html' title='command command'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111691421461095601</id><published>2005-05-23T22:55:00.000-07:00</published><updated>2005-05-23T22:57:38.593-07:00</updated><title type='text'>Basic usage of awk</title><content type='html'>I keep forgetting this,so i posted this.This is how you change the the way awk tokenizes...Here I  use  '/' instead of whitespace&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;echo "http://www.google.com/test" | awk -F/ '{print $4}'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111691421461095601?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111691421461095601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111691421461095601' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111691421461095601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111691421461095601'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/basic-usage-of-awk.html' title='Basic usage of awk'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111684521574460024</id><published>2005-05-23T03:43:00.000-07:00</published><updated>2005-05-23T03:46:55.746-07:00</updated><title type='text'>My remote package installer ;)</title><content type='html'>helps u when you dont want to copy urls from the Redhat RPMS directory .&lt;br /&gt;It depends heavily on the links  output  so it maynot work always..&lt;br /&gt;Didnt work for vedanta... :D&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#!/bin/bash&lt;br /&gt;url="&lt;a href="http://symlin7.india.hp.com/storage/Linux/RedHat/AS3u3/RedHat/RedHat/RPMS/"&gt;http://hostname/AS3u3/RedHat/RPMS/&lt;/a&gt;"&lt;br /&gt;package=`links --dump  ${url} |grep $1 |awk '{print $3}'`&lt;br /&gt;rpm -ivh ${url}$package&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111684521574460024?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111684521574460024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111684521574460024' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111684521574460024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111684521574460024'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/my-remote-package-installer.html' title='My remote package installer ;)'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111588828934698465</id><published>2005-05-12T01:44:00.000-07:00</published><updated>2005-05-12T02:03:46.266-07:00</updated><title type='text'>My Package Remover</title><content type='html'>It all started with me wanting to clean up a system with zillion  packages .&lt;br /&gt;After an half ass attempt to find out what are the packages with biggest size,vedanta pointed me to the rpm's --queryformat option.&lt;br /&gt;&lt;br /&gt;So this solved part of the job,finding out what packages to remove.&lt;br /&gt;So here it is .&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$rpm --queryformat="%{size} %{name}\n" -qa  |sort -n&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;After this obviously when you want to remove a package ,it takes time as the package maybe required by other packages.So i thought of writing a small bash script to do it.So here goes&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#!/bin/sh&lt;br /&gt;removepackage()&lt;br /&gt;{&lt;br /&gt;local fullpackage=$*&lt;br /&gt;if rpm -e $fullpackage 2&gt;/dev/null&lt;br /&gt; then&lt;br /&gt;    echo "Removed the damn package"&lt;br /&gt;    exit&lt;br /&gt;else&lt;br /&gt;    rpm -e $*  2&gt;&amp;amp;1 | awk -F")" '{print $2}' &gt; /tmp/removepackages&lt;br /&gt;                    while read package&lt;br /&gt;&lt;br /&gt;                    do&lt;br /&gt;                    fullpackage="$fullpackage $package"&lt;br /&gt;                    done &lt; /tmp/removepackages&lt;br /&gt;fi &lt;br /&gt; echo $fullpackage&lt;br /&gt; removepackage  $fullpackage &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;removepackage $*&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So thats it just run it with the a package name as an argument and toast your system.&lt;br /&gt;By and by got to know that if you use a pipeline in the while loop above fullpackage scope wont last after the while loop.Bash will put the value it has before it entered the loop thats because while is done using a subshell.&lt;br /&gt;But how does it matter if its a pipe or a redirection??......&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111588828934698465?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111588828934698465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111588828934698465' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111588828934698465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111588828934698465'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/my-package-remover.html' title='My Package Remover'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111580085016684939</id><published>2005-05-11T01:36:00.000-07:00</published><updated>2005-05-11T01:42:14.203-07:00</updated><title type='text'>Using ebuild</title><content type='html'>Now i wanted to try out d4x on vedanta's (&lt;span style="font-size:100%;"&gt;&lt;a href="http://vedanta.freecoolsite.com"&gt;http://vedanta.freecoolsite.com&lt;/a&gt;)&lt;/span&gt; recommendation so i tried to emerge it.But the compile failed .So i looked up gentoo's bugzilla and found the cause.gtk+ 2.6 has a function with the same name as one used by d4x so there is a conflict.&lt;br /&gt;&lt;br /&gt;So i got the patch ( &lt;a href="http://bugs.gentoo.org/attachment.cgi?id=49573"&gt;http://bugs.gentoo.org/attachment.cgi?id=49573&lt;/a&gt; ) from the bugzilla and followed these steps to install the package.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$ebuild /usr/portage/net-misc/d4x/d4x-2.5.0.ebuild fetch&lt;br /&gt;$ebuild /usr/portage/net-misc/d4x/d4x-2.5.0.ebuild unpack&lt;br /&gt;$cd /var/tmp/portage/d4x-2.5.0/work/d4x-2.5.0final/&lt;br /&gt;$patch -p0 &lt; /tmp/d4x.patch $ebuild /usr/portage/net-misc/d4x/d4x-2.5.0.ebuild compile $ebuild /usr/portage/net-misc/d4x/d4x-2.5.0.ebuild install $ebuild /usr/portage/net-misc/d4x/d4x-2.5.0.ebuild qmerge&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's it. Enjoy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111580085016684939?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111580085016684939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111580085016684939' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111580085016684939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111580085016684939'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/using-ebuild.html' title='Using ebuild'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111572744220694637</id><published>2005-05-10T05:07:00.000-07:00</published><updated>2005-05-10T05:17:22.226-07:00</updated><title type='text'>Silencing grep</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ ps aux|grep xinit&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;kalyan   28918  0.0  0.0   1484   472 pts/2    R+   17:37   0:00 grep xinit&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;$ ps aux|grep -q xinit&lt;/span&gt;&lt;br /&gt; &lt;/span&gt;&lt;br /&gt;the -q option to grep is useful when you dont want to see the output in a script but want to just test for a match using the return value.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;if $( ps aux|grep  xinit); then echo "yo"; fi&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-size:100%;"&gt;Now this will try to run the output of that command $( ps aux|grep xinit)&lt;br /&gt;and bash will say&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;&lt;br /&gt;-bash: kalyan: command not found&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;but now when you write a for loop when you have to use it else bash will complain.&lt;br /&gt;So the right thing to do is&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$ if  ps aux|grep  -q xinit; then echo "yo"; fi&lt;br /&gt;&lt;br /&gt;$for mycom in   $(ps aux|grep  xinit); do  echo "yo"; done&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-size:100%;" &gt;I know the examples are weird ;)&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111572744220694637?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111572744220694637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111572744220694637' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111572744220694637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111572744220694637'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/silencing-grep.html' title='Silencing grep'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111571986087056776</id><published>2005-05-10T03:04:00.000-07:00</published><updated>2005-05-10T03:11:00.883-07:00</updated><title type='text'>A thing about nfs</title><content type='html'>Though I thought i should only blog about bash related stuff,i like breaking the rules sometimes.&lt;br /&gt;In case you want a read write mount then you have to set up a few things at server end , basically not to map the root on the client to anonymous on the server.&lt;br /&gt;&lt;br /&gt;Here is the thing you'd like to add to  &lt;span style="color: rgb(0, 0, 153);"&gt;/etc/exports&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;/storage       *(rw,no_root_squash,sync)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111571986087056776?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111571986087056776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111571986087056776' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111571986087056776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111571986087056776'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/thing-about-nfs.html' title='A thing about nfs'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111562127324764467</id><published>2005-05-08T22:51:00.000-07:00</published><updated>2005-05-09T03:27:12.646-07:00</updated><title type='text'>Finding use</title><content type='html'>Finding use for using find&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$ find -size +100000k&lt;br /&gt;./.evolution/mail/local/Inbox&lt;br /&gt;./fun/kernel/src/linux-2.6.11-gentoo-r4/cscope.out&lt;br /&gt;./fun/kernel/src/linux-2.6.11.7/cscope.out&lt;br /&gt;./eclipse.tgz&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ find -size +100000k -and -name 'In*'&lt;br /&gt;./.evolution/mail/local/Inbox&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ find -size +100000k ! -name 'In*'&lt;br /&gt;./fun/kernel/src/linux-2.6.11-gentoo-r4/cscope.out&lt;br /&gt;./fun/kernel/src/linux-2.6.11.7/cscope.out&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ find -size +100000k -or -name 'cscope_maps.vim*'&lt;br /&gt;./.evolution/mail/local/Inbox&lt;br /&gt;./fun/kernel/src/linux-2.6.11-gentoo-r4/cscope.out&lt;br /&gt;./fun/kernel/src/linux-2.6.11.7/cscope.out&lt;br /&gt;./.vim/plugin/cscope_maps.vim&lt;br /&gt;&lt;br /&gt;$ find -amin -1 -name '*.c'&lt;br /&gt;./test.c&lt;br /&gt;&lt;br /&gt;$ find . -name "test.c" -and -maxdepth 1  -exec ls -l   '{}' \;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111562127324764467?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111562127324764467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111562127324764467' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111562127324764467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111562127324764467'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/finding-use.html' title='Finding use'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111528279770207526</id><published>2005-05-05T01:45:00.000-07:00</published><updated>2006-05-05T09:30:56.816-07:00</updated><title type='text'>ulimit</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$ ulimit -a&lt;br /&gt;core file size        (blocks, -c) 0&lt;br /&gt;data seg size         (kbytes, -d) unlimited&lt;br /&gt;file size             (blocks, -f) unlimited&lt;br /&gt;max locked memory     (kbytes, -l) 32&lt;br /&gt;max memory size       (kbytes, -m) unlimited&lt;br /&gt;open files                    (-n) 1024&lt;br /&gt;pipe size          (512 bytes, -p) 8&lt;br /&gt;stack size            (kbytes, -s) 8192&lt;br /&gt;cpu time             (seconds, -t) unlimited&lt;br /&gt;max user processes            (-u) 7168&lt;br /&gt;virtual memory        (kbytes, -v) unlimited&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;For core file generation&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ulimit -c unlimited&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111528279770207526?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111528279770207526/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111528279770207526' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111528279770207526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111528279770207526'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/ulimit.html' title='ulimit'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111528217023055042</id><published>2005-05-05T01:34:00.000-07:00</published><updated>2005-05-05T01:36:37.096-07:00</updated><title type='text'>Named pipes</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$mkfifo pipe&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;On terminal 1&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$cat pipe&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;On terminal 2&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;$cat &gt; pipe&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now you know what i mean&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111528217023055042?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111528217023055042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111528217023055042' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111528217023055042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111528217023055042'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/named-pipes.html' title='Named pipes'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111519378819871632</id><published>2005-05-04T00:58:00.000-07:00</published><updated>2005-05-04T01:03:08.210-07:00</updated><title type='text'>Using file test - Part 2</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;if [ -p "/dev/initctl" ]&lt;br /&gt;        then&lt;br /&gt;                echo "I am the pipe file"&lt;br /&gt;fi&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;if [ -b "/dev/hda" ]&lt;br /&gt;        then&lt;br /&gt;                echo "I am the block file"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;if [ -c "/dev/vc/1" ]&lt;br /&gt;        then&lt;br /&gt;                echo "I am the character file"&lt;br /&gt;fi&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111519378819871632?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111519378819871632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111519378819871632' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111519378819871632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111519378819871632'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/using-file-test-part-2.html' title='Using file test - Part 2'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111519036002094956</id><published>2005-05-03T23:49:00.000-07:00</published><updated>2005-05-04T00:06:00.040-07:00</updated><title type='text'>Using file test - Part 1</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#!/bin/bash&lt;br /&gt;#filetest.sh&lt;br /&gt;&lt;br /&gt;if [ -x "filetest.sh" ]&lt;br /&gt;        then&lt;br /&gt;        echo "filetest.sh is executable"&lt;br /&gt;else&lt;br /&gt;        echo "filetest.sh is not executable"&lt;br /&gt;fi&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;$ sh filetest.sh&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;filetest.sh is not executable&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;$ chmod +x filetest.sh&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 102, 0);"&gt; $ ./filetest.sh&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;filetest.sh is executable&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now time for something interesting ..let me find out the executable files inside my home directory using this.Well i dont like the find options.&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;&lt;br /&gt;cat filetest.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;if [ -d "$1" ]&lt;br /&gt;        then&lt;br /&gt;                :&lt;br /&gt;        else&lt;br /&gt;                echo "A directory expected"&lt;br /&gt;                exit 1;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;for myfile in $( find $1 )&lt;br /&gt;        do&lt;br /&gt;                if [ -x "$myfile" -a -f "$myfile" ]&lt;br /&gt;                then&lt;br /&gt;                        echo "$myfile is executable"&lt;br /&gt;                fi&lt;br /&gt;        done&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111519036002094956?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111519036002094956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111519036002094956' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111519036002094956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111519036002094956'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/using-file-test-part-1.html' title='Using file test - Part 1'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111512187229177720</id><published>2005-05-03T05:04:00.000-07:00</published><updated>2005-05-03T05:04:32.293-07:00</updated><title type='text'>A bash webserver</title><content type='html'>Man this thing rocks.Check it out&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://ufpr.dl.sourceforge.net/sourceforge/mws/mws10.tgz"&gt;http://ufpr.dl.sourceforge.net/sourceforge/mws/mws10.tgz&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111512187229177720?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111512187229177720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111512187229177720' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111512187229177720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111512187229177720'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/bash-webserver.html' title='A bash webserver'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111512079724900192</id><published>2005-05-03T04:30:00.000-07:00</published><updated>2005-05-03T04:46:37.250-07:00</updated><title type='text'>Dancing bars</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;while true; do if(( count % 2 == 0)); then tput clear;  echo '\'; else tput clear ;echo "/"; fi; ((count++)); done&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now i'll use switch case&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;printbar()&lt;br /&gt;{&lt;br /&gt;case $1 in&lt;br /&gt;        '0') echo "/";;&lt;br /&gt;        '1') echo "|";;&lt;br /&gt;        '2') echo '\';;&lt;br /&gt;        '3') echo "-";;&lt;br /&gt;        '4') echo "|";;&lt;br /&gt;        '5') echo '\';;&lt;br /&gt;        '6') echo "-";;&lt;br /&gt;        *) echo "not found";;&lt;br /&gt;esac&lt;br /&gt;}&lt;br /&gt;clear&lt;br /&gt;count=0&lt;br /&gt;while true&lt;br /&gt;        do&lt;br /&gt;        tput cup  10 10&lt;br /&gt;        printbar $(($count % 7))&lt;br /&gt;        (( count++ ))&lt;br /&gt;done&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111512079724900192?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111512079724900192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111512079724900192' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111512079724900192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111512079724900192'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/dancing-bars.html' title='Dancing bars'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111511823639589020</id><published>2005-05-03T03:57:00.000-07:00</published><updated>2005-05-03T04:03:56.396-07:00</updated><title type='text'>Constantly monitor disc usage</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;while true;do du -sm  .;sleep 1;done&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111511823639589020?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111511823639589020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111511823639589020' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111511823639589020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111511823639589020'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/constantly-monitor-disc-usage.html' title='Constantly monitor disc usage'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111502897012069026</id><published>2005-05-02T03:06:00.000-07:00</published><updated>2005-05-02T03:16:23.106-07:00</updated><title type='text'>The truth about -z  and  -n</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-family:courier new;font-size:85%;"  &gt;if [ -z $null ]&lt;br /&gt;then&lt;br /&gt; echo '$null is null'&lt;br /&gt;else&lt;br /&gt; echo '$null file is not null.'&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [ -n $null ]&lt;br /&gt;then&lt;br /&gt; echo '$null file is not null.'&lt;br /&gt;else&lt;br /&gt; echo '$null is null'&lt;br /&gt;fi&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The output is&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-size:85%;" &gt;$$null is null&lt;br /&gt;$$null file is not null.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Not quite as we expected,So we learn that we should always quote the tested string and -n  needs it.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;if [ -z $null ]&lt;br /&gt;then&lt;br /&gt; echo '$null is null'&lt;br /&gt;else&lt;br /&gt; echo '$null file is not null.'&lt;br /&gt;fi&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);font-size:85%;" &gt;&lt;br /&gt;if [ -n "$null" ]&lt;br /&gt;then&lt;br /&gt; echo '$null file is not null.'&lt;br /&gt;else&lt;br /&gt; echo '$null is null'&lt;br /&gt;fi&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111502897012069026?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111502897012069026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111502897012069026' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111502897012069026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111502897012069026'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/05/truth-about-z-and-n.html' title='The truth about -z  and  -n'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111485464408849165</id><published>2005-04-30T02:46:00.000-07:00</published><updated>2007-02-20T01:23:57.573-08:00</updated><title type='text'>Already using the bash power :)</title><content type='html'>&lt;span style="font-size:85%;"&gt;In the  DBUS python code,i came across few examples which had a missing interpreter at the top .&lt;br /&gt;So i sent a mail to mailing list and J5 let me contribute by asking me to submit the patch.&lt;br /&gt;I really like the spirit of Free Software ,i started creating the patches after creating a couple of them.I said&lt;br /&gt;"Wait"...Whats the point of bash if you keep repeating the samething. :)&lt;br /&gt;So here is the script that creates the patch for the missing interpreter.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;for sourcefile in $(ls *.py )&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;do&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;        if  head -n 1  $sourcefile |grep -e '^#!' &amp;&gt; /dev/null &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;        then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;                echo "$sourcefile has some interpretor"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;        else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;                cp $sourcefile ${sourcefile}_orig&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;                cat  ${sourcefile}_orig |  sed -e '1i#!/usr/bin/env python\' -e ''  &gt; $sourcefile&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;                diff -u ${sourcefile}_orig $sourcefile &gt;&gt; examples.patch&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;        fi&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;done&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Yo&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111485464408849165?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111485464408849165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111485464408849165' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111485464408849165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111485464408849165'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/04/already-using-bash-power.html' title='Already using the bash power :)'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111476619728315534</id><published>2005-04-29T02:15:00.000-07:00</published><updated>2005-04-29T02:16:37.283-07:00</updated><title type='text'>strlen of Bash</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);"&gt;$ echo ${#EDITOR}&lt;br /&gt;9&lt;br /&gt;$ echo $EDITOR&lt;br /&gt;/bin/nano&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Yo!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111476619728315534?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111476619728315534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111476619728315534' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111476619728315534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111476619728315534'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/04/strlen-of-bash.html' title='strlen of Bash'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111468136724635572</id><published>2005-04-28T02:19:00.000-07:00</published><updated>2005-04-28T03:12:00.423-07:00</updated><title type='text'>Shell Parameter Expansion</title><content type='html'>This one is big so here I  go.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;${!&lt;var&gt;prefix&lt;/var&gt;*}&lt;br /&gt;&lt;br /&gt;This one expands the variables whose name starts with the prefix.One thing to note is that  '*" is needed as shown below&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;$ echo ${!H*}&lt;br /&gt;HISTCMD HISTFILE HISTFILESIZE HISTSIZE HOME HOSTNAME HOSTTYPE&lt;br /&gt;$ echo ${!HISTCMD}&lt;br /&gt;&lt;br /&gt;echo ${!HISTCMD*}&lt;br /&gt;HISTCMD&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;${#&lt;var&gt;parameter&lt;/var&gt;}&lt;br /&gt;length in characters of the parameter but in case * and @ they refer to number of parameters.&lt;br /&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;$ cat parameter.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;echo ${#1}&lt;br /&gt;echo $(#*}&lt;br /&gt;$./parameter.sh abcdefghijklmnopqrstuvwxyz&lt;br /&gt;26&lt;br /&gt;1&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt; &lt;dl compact="compact"&gt; &lt;dt&gt;&lt;code&gt;${&lt;var&gt;parameter&lt;/var&gt;#&lt;var&gt;word&lt;/var&gt;}&lt;/code&gt; &lt;/dt&gt;&lt;dt&gt;&lt;code&gt;${&lt;var&gt;parameter&lt;/var&gt;##&lt;var&gt;word&lt;/var&gt;}&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/dt&gt;&lt;dt&gt;&lt;code&gt;try to match the word(it can be a pattern) against the parameter at the beginning  and if it matches delete the shortest match&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ cat parametermatch.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;echo ${1#ab*}&lt;br /&gt;echo ${1##ab*}&lt;br /&gt;$ ./parametermatch.sh abcdefghi&lt;br /&gt;cdefghi&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;&lt;dt&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;     &lt;pre&gt;$&lt;/pre&gt;     &lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;   &lt;dt&gt;&lt;br /&gt; &lt;/dt&gt;&lt;dt&gt;&lt;code&gt;${&lt;var&gt;parameter&lt;/var&gt;%&lt;var&gt;word&lt;/var&gt;}&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/dt&gt;&lt;dt&gt;&lt;code&gt;${&lt;var&gt;parameter&lt;/var&gt;%%&lt;var&gt;word&lt;/var&gt;}&lt;/code&gt;&lt;/dt&gt;   &lt;dt&gt;&lt;code&gt;Samething as above but matches and deletes at the end&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;   &lt;dt&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ ./parametermatch.sh abcdefghi&lt;br /&gt;abcdefg&lt;br /&gt;&lt;br /&gt;$ cat parametermatch.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;echo ${1%*hi}&lt;br /&gt;echo ${1%%*hi}&lt;br /&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/dt&gt; &lt;/dl&gt;&lt;br /&gt;&lt;code&gt;${&lt;var&gt;parameter&lt;/var&gt;/&lt;var&gt;pattern&lt;/var&gt;/&lt;var&gt;string&lt;/var&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;$ cat parametermatch.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;echo ${1/pattern/replacepattern}&lt;br /&gt;$ ./parametermatch.sh hipattern&lt;br /&gt;hireplacepattern&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111468136724635572?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111468136724635572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111468136724635572' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111468136724635572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111468136724635572'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/04/shell-parameter-expansion.html' title='Shell Parameter Expansion'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111467981009632443</id><published>2005-04-28T01:31:00.000-07:00</published><updated>2005-04-28T02:16:50.096-07:00</updated><title type='text'>Bash Expansions</title><content type='html'>I'll come back to numbers before i post some cool features of bash.&lt;br /&gt;Note that the  '$' at the beginning of the line denotes the prompt.&lt;br /&gt;&lt;br /&gt;1.Brace Expansion&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ echo alumn{a,i,ae,us}&lt;br /&gt;alumna alumni alumnae alumnus&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;2.Tilde Exansion.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ echo ~&lt;br /&gt;/home/kalyan&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;3.Command substitution&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ ls $(which ls)&lt;br /&gt;/bin/ls&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;Backticks also..&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;$ ls `which ls`&lt;br /&gt;/bin/ls&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;4.Filename exapansion&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;$ ls s*&lt;br /&gt;sd  shift.sh  string.sh  stringcmp.sh&lt;br /&gt;$ ls s?&lt;br /&gt;sd&lt;br /&gt;$ ls s[hd]*&lt;br /&gt;sd  shift.sh&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;5.Arithmetic Ex&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;pansion&lt;/span&gt;&lt;br /&gt;$ n=7&lt;br /&gt;$ ((n=n+10))&lt;br /&gt;$ echo $n&lt;br /&gt;17&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;6.Paramenter expansion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;$ ps=${ps:=lambadamda}&lt;br /&gt;$ echo $ps&lt;br /&gt;lambadamda&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111467981009632443?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111467981009632443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111467981009632443' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111467981009632443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111467981009632443'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/04/bash-expansions.html' title='Bash Expansions'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12495806.post-111467220031575382</id><published>2005-04-28T00:07:00.000-07:00</published><updated>2005-04-28T22:33:06.720-07:00</updated><title type='text'>Bash Comparisons</title><content type='html'>So here is the bottomline as far comparing strings and  integers in bash is concerned.&lt;br /&gt;You want to compare strings use&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;[[ $stringa &lt; $stringb ]]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You want to compare numbers use&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;(( $numbera &lt; $numberb ))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This will take you a long way without much heartburns. :)&lt;br /&gt;Now lets try out a few examples to understand this thing better.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#string.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;EQUAL="equal"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;if [ $EQUAL  == "equal" ]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;      then&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;      echo "I am equal"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;      else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;      echo "I am not equal"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;fi&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;$ ./string.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;I am equal&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Now lets try something more now see if 'a' &lt; 'b' &lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#stringcmp.sh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;A="a"&lt;br /&gt;&lt;br /&gt;if [ $A  &lt; "b" ]        &lt;br /&gt;    then        &lt;br /&gt;    echo "a is lesser than b"        &lt;br /&gt;else        &lt;br /&gt;    echo "Something went wrong"&lt;br /&gt;fi &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;$ ./stringcmp.sh&lt;br /&gt;./stringcmp.sh: line 5: b: No such file or directory&lt;br /&gt;Something went wrong&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="down" style="display: block;" id="formatbar_CreateLink" title="Link" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);"&gt;&lt;/span&gt;&lt;br /&gt;Ah so we cant do that. :) . So we try '[[ ]]'&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;#!/bin/bash&lt;br /&gt;#stringcmp.sh&lt;br /&gt;A="a"&lt;br /&gt;&lt;br /&gt;if [[ $A  &lt; "b" ]]        &lt;br /&gt;    then        &lt;br /&gt;    echo "a is lesser than b"        &lt;br /&gt;else        &lt;br /&gt;    echo "Something went wrong"&lt;br /&gt;fi  &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;$ ./stringcmp.sh&lt;br /&gt;a is lesser than b&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;So a more comprehensive example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;#stringcmp.sh&lt;br /&gt;A="a"&lt;br /&gt;C="c"&lt;br /&gt;B="b"&lt;br /&gt;&lt;br /&gt;if [[ $A &lt; "b" ]]&lt;br /&gt;then&lt;br /&gt;    echo "a is lesser than b"&lt;br /&gt;else&lt;br /&gt;    echo "Something went wrong"&lt;br /&gt;fi&lt;br /&gt;if [[ $C &lt; "b" ]]&lt;br /&gt;    then&lt;br /&gt;    echo "Something went wrong"&lt;br /&gt;else&lt;br /&gt;    echo "c is not lesser than b"&lt;br /&gt;fi&lt;br /&gt;if [[ $B &lt; "b" ]]&lt;br /&gt;    then echo "Something went wrong"&lt;br /&gt;else&lt;br /&gt;        if [[ $B == "b" ]]&lt;br /&gt;        then&lt;br /&gt;        echo "b is equal to b"&lt;br /&gt;        fi&lt;br /&gt;fi &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;br /&gt;$ ./stringcmp.sh&lt;br /&gt;a is lesser than b&lt;br /&gt;c is not  lesser than b&lt;br /&gt;b is equal to b&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 153);"&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;Numbers are pretty straightforward as they only work with circular parenthesis "(())".&lt;br /&gt;So you cant use the examples listed above to compare numbers.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12495806-111467220031575382?l=bashrules.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bashrules.blogspot.com/feeds/111467220031575382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12495806&amp;postID=111467220031575382' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111467220031575382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12495806/posts/default/111467220031575382'/><link rel='alternate' type='text/html' href='http://bashrules.blogspot.com/2005/04/bash-comparisons.html' title='Bash Comparisons'/><author><name>Tatavarty Kalyan</name><uri>http://www.blogger.com/profile/16353814476157606302</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
