<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Notes 2 Myself</title>
	<atom:link href="http://irfanworld.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://irfanworld.wordpress.com</link>
	<description>Remember: Your idea is what gets you in the game; your competitive advantage is what keeps you there. If you can't figure out how to stay ahead in your market, start looking for a new one.</description>
	<pubDate>Tue, 16 Sep 2008 08:27:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unix Shell Scripting</title>
		<link>http://irfanworld.wordpress.com/2008/09/16/unix-shell-scripting/</link>
		<comments>http://irfanworld.wordpress.com/2008/09/16/unix-shell-scripting/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 07:13:06 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[#!/bin/sh]]></category>

		<category><![CDATA[awk]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[bourne shell]]></category>

		<category><![CDATA[bs]]></category>

		<category><![CDATA[echo]]></category>

		<category><![CDATA[expression]]></category>

		<category><![CDATA[grep]]></category>

		<category><![CDATA[sed]]></category>

		<category><![CDATA[shell]]></category>

		<category><![CDATA[shell programing]]></category>

		<category><![CDATA[shell scripting]]></category>

		<category><![CDATA[tee]]></category>

		<category><![CDATA[test]]></category>

		<category><![CDATA[Unix]]></category>

		<category><![CDATA[unix shell]]></category>

		<category><![CDATA[unix shell programming]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/?p=59</guid>
		<description><![CDATA[This post will help administrator and novice UNIX programmer to understand and write strong as well as useful shell programs. I will talks on shell syntax and few simple day-to-day utilities for UNIX. Will discussing mainly Bourn shell because of its widely acclaimed popularity and usage among the UNIX world.
Many standard utilities (rdist, make, cron, [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">This post will help administrator and novice UNIX programmer to understand and write strong as well as useful shell programs. I will talks on shell syntax and few simple day-to-day utilities for UNIX. Will discussing mainly Bourn shell because of its widely acclaimed popularity and usage among the UNIX world.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Many standard utilities (rdist, make, cron, etc.) allow you to specify a command to run at a certain time. Usually, this command is simply passed to the Bourne shell, which means that you can execute whole scripts, should you choose to do so. Steve Bourne, wrote the Bourne shell which appeared in the Seventh Edition Bell Labs Research version of Unix. </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Lastly, UNIX runs Bourne shell scripts when it boots. If you want to modify the boot-time behavior of a system, you need to learn to write and modify Bourne shell scripts. It said there are 95% shell code written in Bourne shell. Code written in Bourne shell is compatible with shell scripting like ksh, bash &amp; zsh. That means with minimal or no change one could port shell script written in Bourne shell to ksh or bash or zsh.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">*Bash is popular among Linux users. </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">There are couple of other shells available which I will not be talking are C shell ( Used by C program to create programming rich shell) this is incompatible to Bourne shell. The C shell, csh, and its variant tcsh is a fine interactive shell (I use tcsh), but is a lousy shell for writing scripts.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Lets understand what is an executable files, they also know as program or binary executables, This files are machine readable files and human eyes can not make sense out of it. Others only contain text, knows as script. They are interpreter scripts like awk, sed, perl and many more.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3><span>Learning Shell Scripting</span></h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The first line of any script must begin with #!, followed by the name of the interpreter. Some versions of UNIX allow whitespace between #! and the name of the interpreter. Others do not. Hence, if you want your script to be portable, leave out the blank.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A script, like any file that can be run as a command, needs to be executable: save this script as rotatelog and run</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">chmod +x rotatelog<br />
to make it executable.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">You can now run it by running<br />
./rotatelog</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Unlike some other operating systems, UNIX allows any program to be used as a script interpreter. This is why people talk about &#8220;a Bourne shell script&#8221; or &#8220;an awk script.&#8221; One might even write a more script, or an ls script (though the latter wouldn&#8217;t be terribly useful). Hence, it is important to let Unix know which program will be interpreting the script.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">When Unix tries to execute the script, it sees the first two characters (#!) and knows that it is a script. It then reads the rest of the line to find out which program is to execute the script. For a Bourne shell script, this will be /bin/sh. Hence, the first line of our script must be</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">After the command interpreter, you can have one, and sometimes more, options. Some flavors of Unix only allow one, though, so don&#8217;t assume that you can have more.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Variables</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sh allows you to have variables, just like any programming languages. Variables do not need to be declared. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">To set a sh variable, use VAR=value</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">And to use the value of the variable later, use $VAR or ${VAR}</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The latter syntax is useful if the variable name immediately followed by other text:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">COLOR=yellow </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo This looks $COLORish </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo This seems ${COLOR}ish</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">prints</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This looks </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This seems yellowish</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">There is only one type of variable in sh: strings. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This is somewhat limited, but is sufficient for most purposes.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Local vs. environment variables</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A sh variable can be either a local variable or an environment variable. They both work the same way; the only difference lies in what happens when the script runs another program (which, as we saw earlier, it does all the time).</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Environment variables are passed to subprocesses. Local variables are not.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">By default, variables are local. To turn a local variable into an environment variable, </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">use</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">export VAR</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Here&#8217;s a simple wrapper for a program:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">NETSCAPE_HOME=/usr/imports/libdata </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">CLASSPATH=$NETSCAPE_HOME/classes </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">export CLASSPATH $NETSCAPE_HOME/bin/netscape.bin</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Here, NETSCAPE_HOME is a local variable; CLASSPATH is an environment variable. CLASSPATH will be passed to netscape.bin (netscape.bin uses the value of this variable to find Java class files); NETSCAPE_HOME is a convenience variable that is only used by the wrapper script; netscape.bin doesn&#8217;t need to know about it, so it is kept local.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The only way to unexport a variable is to unset it:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">unset VAR</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This removes the variable from the shell&#8217;s symbol table, effectively making as if it had never existed; as a side effect, the variable is also unexported.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Also, if you have a function by the same name as the variable, unset will also delete that function. Since you may want to use this variable later, it is better not to define it in the first place.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Also, note that if a variable was passed in as part of the environment, it is already an environment variable when your script starts running. If there is a variable that you really don&#8217;t want to pass to any subprocesses, you should unset it near the top of your script. This is rare, but it might conceivably happen.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If you refer to a variable that hasn&#8217;t been defined, sh substitutes the empty string.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo aaa $FOO bbb </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo xxx${FOO}yyy</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">prints</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">aaa bbb xxxyyy</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Special variables</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sh treats certain variables specially: some are set for you when your script runs, and some affect the way commands are interpreted.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Command-line arguments</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The most useful of these variables are the ones referring to the command-line arguments. $1 refers to the first command-line argument (after the name of the script), $2 refers to the second one, and so forth, up to $9.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If you have more than nine command-line arguments, you can use the shift command: this discards the first command-line argument, and bumps the remaining ones up by one position: $2 becomes $1, $8 becomes $7, and so forth.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The variable $0 (zero) contains the name of the script (argv[0] in C programs).</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Often, it is useful to just list all of the command-line arguments. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">For this, sh provides the variables $* (star) and $@ (at). Each of these expands to a string containing all of the command-line arguments, as if you had used $1 $2 $3&#8230;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The difference between $* and $@ lies in the way they behave when they occur inside <a href="#double-quotes" target="_blank"><span style="text-decoration:none;color:#000000;">double quotes</span></a>: $* behaves in the normal way, whereas $@ creates a separate double-quoted string for each command-line argument. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">That is, &#8220;$*&#8221; behaves as if you had written &#8220;$1 $2 $3&#8243;, whereas &#8220;$@&#8221; behaves as if you had written &#8220;$1&#8243; &#8220;$2&#8243; &#8220;$3&#8243;.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Finally, $# contains the number of command-line arguments that were given.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Other special variables</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">$? gives the exit status of the last command that was executed. This should be zero if the command exited normally.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">$- lists all of the options with which sh was invoked. See sh(1) for details.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">$$ holds the PID of the current process.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">$! holds the PID of the last command that was executed in the background.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">$IFS (Input Field Separator) determines how sh splits strings into words.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Quasi-variable constructs</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The ${VAR} construct is actually a special case of a more general class of constructs:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">${VAR:-expression} </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Use default value: if VAR is set and non-null, expands to $VAR. Otherwise, expands to expression. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">${VAR:=expression} </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Set default value: if VAR is set and non-null, expands to $VAR. Otherwise, sets VAR to expression and expands to expression. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">${VAR:?[expression]} </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If VAR is set and non-null, expands to $VAR. Otherwise, prints expression to standard error and exits with a non-zero exit status. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">${VAR:+expression} </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If VAR is set and non-null, expands to the empty string. Otherwise, expands to expression. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">${#VAR} </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Expands to the length of $VAR. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The above patterns test whether VAR is set and non-null. Without the colon, they only test whether VAR is set.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Pattern-matching</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sh supports a limited form of pattern-matching. The operators are</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">* Matches zero or more characters. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">? Matches exactly one character. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">[range] Matches any character in range. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Range can be either a list of characters that match, or two endpoints separated by a dash: [ak3] matches either a, k, or 3; [a-z] matches any character in the range a through z; [a-mz] matches either a character in the range a through m, or z. If you wish to include a dash as part of the range, it must be the first character, e.g., [-p] will match either a dash or p. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">When an expression containing these characters occurs in the middle of a command, sh substitutes the list of all files whose name matches the pattern. This is known as &#8220;globbing.&#8221; Otherwise, these are used mainly in the <a href="#case" target="_blank"><span style="text-decoration:none;color:#000000;">case</span></a> construct.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">As a special case, when a glob begins with * or ?, it does not match files that begin with a dot. To match these, you need to specify the dot explicitly (e.g., .*, /tmp/.*).</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Note to MS-DOS users: under MS-DOS, the pattern *.* matches every file. In sh, it matches every file that contains a dot.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Quoting</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If you say something like</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo * MAKE $$$ FAST *</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">it won&#8217;t do what you want: first of all, sh will expand the *s and replace them with a list of all the files in the current directory. Then, since any number of tabs or blanks can separate words, it will compress the three spaces into one. Finally, it will replace the first instance of $$ with the PID of the shell. This is where quoting comes in.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sh supports several types of quotes. Which one you use depends on what you want to do.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Backslash</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Just as in C strings, a backslash (&#8220;\&#8221;) removes any special meaning from the character that follows. If the character after the backslash isn&#8217;t special to begin with, the backslash has no effect. The backslash is itself special, so to escape it, just double it: \\.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Single quotes</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Single quotes, such as &#8216;foo&#8217; work pretty much the way you&#8217;d expect: anything inside them (except a single quote) is quoted. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">You can say</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo &#8216;* MAKE $$$ FAST *&#8217;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">and it&#8217;ll come out the way you want it to.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Note that a backslash inside single quotes also loses its special meaning, so you don&#8217;t need to double it. There is no way to have a single quote inside single quotes.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Double quotes, such as</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&#8220;foo&#8221;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">preserve spaces and most special characters. However, variables and <a href="#backquote" target="_blank"><span style="text-decoration:none;color:#000000;">backquoted expressions</span></a> are expanded and replaced with their value.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If you have an expression within backquotes (also known as backticks), e.g.,</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">`cmd`</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">the expression is evaluated as a command, and replaced with whatever the expression prints to its standard output. Thus,</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo You are `whoami`</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">prints</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">You are irfan</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Built-in commands</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sh understands several built-in commands, i.e., commands that do not correspond to any program. These commands include:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">{ commands ; }, ( commands ) </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Execute commands in a subshell. That is, run them as if they were a single command. This is useful when <a href="#io-redirection" target="_blank"><span style="text-decoration:none;color:#000000;">I/O redirection</span></a> is involved, since you can pipe data to or from a mini-script inside a pipeline.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The { commands; } variant is somewhat more efficient, since it doesn&#8217;t spawn a true subshell. This also means that if you set variables inside of it, the changes will be visible in the rest of the script. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">: (colon) </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Does nothing. This is generally seen as </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">: ${VAR:=default}</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">. filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The dot command reads in the specified filename, as if it had occurred at that place in the script. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">bg [job], fg [job] </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">bg runs the specified job (or the current job, if none is specified) in the background. fg resumes the specified job (or the current job, if none is specified) in the foreground. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Jobs are specified as %number. The jobs command lists jobs. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">cd [dir] </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Sets the current directory to dir. If dir is not specified, sets the current directory to the home directory. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">pwd </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Prints the current directory. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo args </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Prints args to standard output. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">eval args </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Evaluates args as a sh expression. This allows you to construct a string on the fly (e.g., using a variable that holds the name of a variable that you want to set) and execute it. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">exec command </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Runs the specified command, and replaces the current shell with it. That is, nothing after the exec statement will be executed, unless the exec itself fails. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">exit [n] </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Exit the current shell with exit code n. This defaults to zero. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">kill [-sig] %job </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Send signal sig to the specified job. sig can be either numeric or symbolic. kill -l lists all available signals. By default, sig is SIGTERM (15). </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">read name&#8230; </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Reads one line from standard input and assigns it to the variable name. If several variables name1, name2, name3 etc. are specified, then the first word of the line read is assigned to name1, the second to name2, and so forth. Any remaining words are assigned to the last variable. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">set [+/-flag] [arg] </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">With no arguments, prints the values of all variables.set -x turns on the x option to sh; set +x turns it off.set args&#8230; sets the command-line arguments to args.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">test expression </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Evaluates a boolean expression and exits with an exit code of zero if it is true, or non-zero if it is false. See <a href="#test" target="_blank"><span style="text-decoration:none;color:#000000;">test</span></a> for more details. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">trap [command sig]&#8230; </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If signal sig is sent to the shell, execute command. This is useful for exiting cleanly (e.g., removing temporary files etc.) when the script is interrupted. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">ulimit </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Print or set system limits on resource usage. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">umask [nnn] </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Sets the umask to nnn (an octal number). With no argument, prints the current umask. This is most useful when you want to create files, but want to restrict who can read or write them. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">wait [n] </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Wait for the background process whose PID is n to terminate. With no arguments, waits for all of the background processes to terminate. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Bear in mind that the list of builtins varies from one implementation to another, so don&#8217;t take this list as authoritative.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Flow control</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sh supports several flow-control constructs, which add power and flexibility to your scripts.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:14pt;font-family:Verdana;">if</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The if statement is a simple conditional. You&#8217;ve seen it in every programming language. Its syntax is</span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">if condition ; then<br />
commands<br />
[elif condition ; then<br />
commands]&#8230;<br />
[else<br />
commands]<br />
fi</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">That is, an if-block, optionally followed by one or more elif-blocks (elif is short for &#8220;else if&#8221;), optionally followed by an else-block, and terminated by fi.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The if statement pretty much does what you&#8217;d expect: if condition is true, it executes the if-block. Otherwise, it executes the else-block, if there is one. The elif construct is just syntactic sugar, to let you avoid nesting multiple if statements.</span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">myname=`whoami` </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">if [ $myname = root ]; then </span></p>
<p style="margin:0 0 .0001pt 1in;"><span style="font-size:10pt;font-family:Arial;">echo &#8220;Welcome to FooSoft 3.0&#8243; </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">else </span></p>
<p style="margin:0 0 .0001pt 1in;"><span style="font-size:10pt;font-family:Arial;">echo &#8220;You must be root to run this script&#8221; </span></p>
<p style="margin:0 0 .0001pt 1in;"><span style="font-size:10pt;font-family:Arial;">exit 1 </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">fi</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The more observant among you (or those who are math majors) are thinking, &#8220;Hey! You forgot to include the square brackets in the syntax definition!&#8221;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Actually, I didn&#8217;t: [ is actually a command, /bin/[, and is another name for the test command. See <a href="#test" target="_blank"><span style="text-decoration:none;color:#000000;">below</span></a> for details.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This is why you shouldn't call a test program test: if you have ``.'' at the end of your path, as you should, executing test will run /bin/test.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The condition can actually be any command. If it returns a zero exit status, the condition is true; otherwise, it is false. Thus, you can write things like</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">user=arnie </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">if grep $user /etc/passwd; then </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">echo "$user has an account" </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">else </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">echo "$user doesn't have an account" </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">fi</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>while</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The while statement should also be familiar to you from any number of other programming languages. Its syntax in sh is</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">while condition; do<br />
commands<br />
done</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">As you might expect, the while loop executes commands as long as condition is true. Again, condition can be any command, and is true if the command exits with a zero exit status.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A while loop may contain two special commands: break and continue.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">break exits the while loop immediately, jumping to the next statement after the done.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">continue skips the rest of the body of the loop, and jumps back to the top, to where condition is evaluated.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>for</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The for loop iterates over all of the elements in a list. Its syntax is</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">for var in list; do<br />
commands<br />
done</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">list is zero or more words. The for construct will assign the variable var to each word in turn, then execute commands. For example:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#!/bin/sh </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">for i in foo bar baz "do be do"; do </span></p>
<p style="margin:0 0 .0001pt .5in;"><span style="font-size:10pt;font-family:Arial;">echo "$i" </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">done</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">will print</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">foo bar baz do be do</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A for loop may also contain break and continue statements. They work the same way as in the while loop.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Case</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The case construct works like C's switch statement, except that it matches patterns instead of numerical values. Its syntax is</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">case expression in<br />
pattern)<br />
commands<br />
;;<br />
...<br />
esac</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">expression is a string; this is generally either a variable or a backquoted command.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">pattern is a glob pattern (see <a href="#globbing" target="_blank"><span style="text-decoration:none;color:#000000;">globbing</span></a>).</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The patterns are evaluated in the order in which they are seen, and only the first pattern that matches will be executed. Often, you'll want to include a ``none of the above'' clause; to do this, use * as your last pattern.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>IO</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A command's input and/or output may be redirected to another command or to a file. By default, every process has three file descriptors: standard input (0), standard output (1) and standard error (2). By default, each of these is connected to the user's terminal.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">However, one can do many interesting things by redirecting one or more file descriptor:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&lt; filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Connect standard input to the file filename. This allows you to have a command read from the file, rather than having to type its input in by hand. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&gt; filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Connect standard output to the file filename. This allows you to save the output of a command to a file. If the file does not exist, it is created. If it does exist, it is emptied before anything happens. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">(Exercise: why doesn't cat * &gt; zzzzzzz work the way you'd expect?)</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&gt;&gt; filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Connects standard output to the file filename. Unlike &gt;, however, the output of the command is appended to filename. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&lt;&lt;word </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This construct isn't used nearly as often as it could be. It causes the command's standard input to come from... standard input, but only until word appears on a line by itself. Note that there is no space between &lt;&lt; and word.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This can be used as a mini-file within a script, e.g., </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">cat &gt; foo.c &lt;&lt;EOT </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">#include &lt;stdio.h&gt; </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">main() { </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">printf("Hello, world!\n"); </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">} EOT</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">It is also useful for printing multiline messages, e.g.:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">line=13 cat &lt;&lt;EOT An error occurred on line $line. See page 98 of the manual for details. EOT</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">As this example shows, by default, &lt;&lt; acts like double quotes (i.e., variables are expanded). If, however, word is quoted, then &lt;&lt; acts like single quotes.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&lt;&amp;digit </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Use file descriptor digit as standard input. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&gt;&amp;digit </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Use file descriptor digit as standard output. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&lt;&amp;- </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Close standard input. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">&gt;&amp;- </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Close standard output. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">command1 | command2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Creates a pipeline: the standard output of command1 is connected to the standard input of command2. This is functionally identical to </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">command1 &gt; /tmp/foo<br />
command2 &lt; /tmp/foo</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">except that no temporary file is created, and both commands can run at the same time</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">There is a proverb that says, ``A temporary file is just a pipe with an attitude and a will to live.'' Any number of commands can be pipelined together.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">command1 &amp;&amp; command2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Execute command1. Then, if it exited with a zero (true) exit status, execute command2. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">command1 || command2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Execute command1. Then, if it exited with a non-zero (false) exit status, execute command2. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If any of the redirection constructs is preceded by a digit, then it applies to the file descriptor with that number, rather than the default (0 or 1, as the case may be). For instance,</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">command 2&gt;&amp;1 &gt; filename</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">associates file descriptor 2 (standard error) with the same file as file descriptor 1 (standard output), then redirects both of them to filename.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">This is also useful for printing error messages:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo "Danger! Danger Will Robinson!" 1&gt;&amp;2</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Note that I/O redirections are parsed in the order they are encountered, from left to right. This allows you to do fairly tricky things, including throwing out standard output, and piping standard output to a command.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>Functions</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">When a group of commands occurs several times in a script, it is useful to define a function. Defining a function is a lot like creating a mini-script within a script.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A function is defined using</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">name () {<br />
commands<br />
}</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">and is invoked like any other command:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">name args...</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">You can redirect a function's I/O, embed it in backquotes, etc., just like any other command.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">One way in which functions differ from external scripts is that the shell does not spawn a subshell to execute them. This means that if you set a variable inside a function, the new value will be visible outside of the function.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A function can use return n to terminate with an exit status of n. Obviously, it can also exit n, but that would terminate the entire script.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Function arguments</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">A function can take command-line arguments, just like any script. Intuitively enough, these are available through $1, $2... $9 just like the main script.</span></p>
<h3>Useful utilities</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">There are a number of commands that aren't part of sh, but are often used inside sh scripts. These include:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">basename</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">basename pathname prints the last component of pathname:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">basename /foo/bar/baz</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">prints</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">baz</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">dirname</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The complement of basename: dirname pathname prints all but the last component of pathname, that is the directory part: pathname:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">dirname /foo/bar/baz</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">prints</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">/foo/bar</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">/bin/[ is another name for /bin/test. It evaluates its arguments as a boolean expression, and exits with an exit code of 0 if it is true, or 1 if it is false.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">If test is invoked as [, then it requires a closing bracket ] as its last argument. Otherwise, there must be no closing bracket.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">test understands the following expressions, among others:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-e filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if filename exists. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-d filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if filename exists and is a directory. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-f filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if filename exists and is a plain file. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-h filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if filename exists and is a symbolic link. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-r filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if filename exists and is readable. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-w filename </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if filename exists and is writable. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-n string </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the length of string is non-zero. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">-z string </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the length of string is zero. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">string </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if string is not the empty string. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">s1 = s2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the strings s1 and s2 are identical. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">s1 != s2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the strings s1 and s2 are not identical. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">n1 -eq n2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the numbers n1 and n2 are equal. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">n1 -ne n2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the numbers n1 and n2 are not equal. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">n1 -gt n2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the number n1 is greater than n2. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">n1 -ge n2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the number n1 is greater than or equal to n2. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">n1 -lt n2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the number n1 is less than n2. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">n1 -le n2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if the number n1 is less than or equal to n2. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">! expression </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Negates expression, that is, returns true iff expression is false. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">expr1 -a expr2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if both expressions, expr1 and expr2 are true. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">expr1 -o expr2 </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">True if either expression, expr1 or expr2 is true. </span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">( expression )</span><span style="font-size:10pt;font-family:Verdana;"> </span></p>
<h3>True if expression is true. This allows one to nest expressions.</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Note that lazy evaluation does not apply, since all of the arguments to test are evaluated by sh before being passed to test. If you stand to benefit from lazy evaluation, use nested ifs.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>echo</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo is a built-in in most implementations of sh, but it also exists as a standalone command.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo simply prints its arguments to standard output. It can also be told not to append a newline at the end: under BSD-like flavors of Unix, use</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">echo -n &#8220;string&#8221;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Under SystemV-ish flavors of Unix, use</span></p>
<p><span style="font-size:10pt;font-family:Arial;">echo &#8220;string\c&#8221;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>awk</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Awk (and its derivatives, nawk and gawk) is a full-fledged scripting language. Inside sh scripts, it is generally used for its ability to split input lines into fields and print one or more fields. For instance, the following reads /etc/passwd and prints out the name and uid of each user:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">awk -F : &#8216;{print $1, $3 }&#8217; /etc/passwd</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The -F : option says that the input records are separated by colons. By default, awk uses whitespace as the field separator.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>sed</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Sed (stream editor) is also a full-fledged scripting language, albeit a less powerful and more convoluted one than awk. In sh scripts, sed is mainly used to do string substitution: the following script reads standard input, replaces all instances of &#8220;foo&#8221; with &#8220;bar&#8221;, and writes the result to standard output:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">sed -e &#8217;s/foo/bar/g&#8217;</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The trailing g says to replace all instances of &#8220;foo&#8221; with &#8220;bar&#8221; on a line. Without it, only the first instance would be replaced.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;"> </span></p>
<h3>tee</h3>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">tee [-a] filename reads standard input, copies it to standard output, and saves a copy in the file filename.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">By default, tee empties filename before it begins. With the -a option, it appends to filename.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Debugging</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">Unfortunately, there are no symbolic debuggers such as gdb for sh scripts. When you&#8217;re debugging a script, you&#8217;ll have to rely the tried and true method of inserting trace statements, and using some useful options to sh:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The -n option causes sh to read the script but not execute any commands. This is useful for checking syntax.</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">The -x option causes sh to print each command to standard error before executing it. Since this can generate a lot of output, you may want to turn tracing on just before the section that you want to trace, and turn it off immediately afterward:</span></p>
<p style="margin:0 0 .0001pt;"><span style="font-size:10pt;font-family:Arial;">set -x # XXX - What&#8217;s wrong with this code? grep $user /etc/passwd 1&gt;&amp;2 &gt; /dev/null set +x</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/59/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/59/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=59&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2008/09/16/unix-shell-scripting/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>Start using PostgreSQL now….</title>
		<link>http://irfanworld.wordpress.com/2008/05/19/start-using-postgresql-now%e2%80%a6/</link>
		<comments>http://irfanworld.wordpress.com/2008/05/19/start-using-postgresql-now%e2%80%a6/#comments</comments>
		<pubDate>Mon, 19 May 2008 02:10:04 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[connect PostgeSQL from Perl]]></category>

		<category><![CDATA[DB]]></category>

		<category><![CDATA[LINUX]]></category>

		<category><![CDATA[Opensource]]></category>

		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Post]]></category>

		<category><![CDATA[PostgreSQL]]></category>

		<category><![CDATA[PostgreSQL vs Oracle]]></category>

		<category><![CDATA[PSQL tricks]]></category>

		<category><![CDATA[why PostgreSQL is better than Oracle]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/?p=44</guid>
		<description><![CDATA[Spend 10 minutes and have PostgreSQL on your own lilo flavor
Purpose of this article to give jump starts to install and performed basic PostgreSQL (pgsql) administrator / user job.
Download binaries from this location ftp://ftp.postgresql.org/pub/source/v8.3.1/postgresql-8.3.1.tar.gz
tar -xzvf postgresql-8.3.1.tar.gz
./configure
gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data &#62;logfile 2&#62;&#38;1 &#38;
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
You are all set [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Spend 10 minutes and have PostgreSQL on your own lilo flavor</strong></p>
<p>Purpose of this article to give jump starts to install and performed basic PostgreSQL (pgsql) administrator / user job.</p>
<p>Download binaries from this location ftp://ftp.postgresql.org/pub/source/v8.3.1/postgresql-8.3.1.tar.gz</p>
<p>tar -xzvf postgresql-8.3.1.tar.gz</p>
<p>./configure<br />
gmake<br />
su<br />
gmake install<br />
adduser postgres<br />
mkdir /usr/local/pgsql/data<br />
chown postgres /usr/local/pgsql/data<br />
su - postgres<br />
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data<br />
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data &gt;logfile 2&gt;&amp;1 &amp;<br />
/usr/local/pgsql/bin/createdb test<br />
/usr/local/pgsql/bin/psql test</p>
<p>You are all set with test database, go ahead and start exploring sql commands on that<br />
$ psql test</p>
<p>If you leave off the database name then it will default to your user account name.</p>
<p>In psql, you will be greeted with the following message:<br />
Welcome to psql 8.3.1, the PostgreSQL interactive terminal.<br />
Type: \copyright for distribution terms<br />
\h for help with SQL commands<br />
\? for help with psql commands<br />
\g or terminate with semicolon to execute query<br />
\q to quit</p>
<p>test=# create sequence pk_seq;<br />
CREATE SEQUENCE</p>
<p>test=# create table my_data (<br />
test(# data_pk integer DEFAULT nextval(&#8217;pk_seq&#8217;::text) NOT NULL,<br />
test(# my_value integer<br />
test(# );<br />
CREATE TABLE</p>
<p>test=# insert into my_data (my_value) values (1);<br />
INSERT 17240 1<br />
test=# select * from my_data;<br />
data_pk | my_value<br />
&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-<br />
1 |        1<br />
(1 row)</p>
<p>test=# insert into my_data (my_value) values (2);<br />
INSERT 17241 1<br />
test=# select * from my_data;<br />
data_pk | my_value<br />
&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-<br />
1 |        1<br />
2 |        2<br />
(2 rows)</p>
<p>test=# \d<br />
List of relations<br />
Schema |  Name   |   Type   |  Owner<br />
&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-<br />
public | my_data | table    | postgres<br />
public | pk_seq  | sequence | postgres<br />
(2 rows)</p>
<p>test=# \d my_data<br />
Table &#8220;public.my_data&#8221;<br />
Column  |  Type   |                Modifiers<br />
&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
data_pk  | integer | not null default nextval(&#8217;pk_seq&#8217;::text)<br />
my_value | integer |</p>
<p>test=# \q<br />
[mst3k@hera ~]$</p>
<p><strong>Spend 10 more minutes and learn how to connect PostgeSQL from Perl</strong></p>
<p>[ ~]$ cat my_data.pl<br />
#!/usr/bin/perl</p>
<p>use strict;</p>
<p>use DBI;</p>
<p>main:<br />
{<br />
my $dbargs = {AutoCommit =&gt; 0, PrintError =&gt; 1};</p>
<p>my $dbh =<br />
DBI-&gt;connect(&#8221;dbi:Pg:dbname=test;host=localhost;port=5432;&#8221;,<br />
&#8220;postgres&#8221;,<br />
&#8220;&#8221;,<br />
$dbargs);</p>
<p>my $sql = &#8220;select * from my_data&#8221;;<br />
my $sth = $dbh-&gt;prepare($sql);<br />
if ($dbh-&gt;err()) { die &#8220;prepare:\n$DBI::errstr\n&#8221;; }</p>
<p>$sth-&gt;execute();<br />
if ($dbh-&gt;err()) { die &#8220;execute:\n$DBI::errstr\n&#8221;; }</p>
<p>while(my $hr = $sth-&gt;fetchrow_hashref())<br />
{<br />
print &#8220;pk: $hr-&gt;{data_pk} value: $hr-&gt;{my_value}\n&#8221;;<br />
}<br />
$dbh-&gt;disconnect();</p>
<p><strong>Spend 10 more minutes to learn few more SQL tricks</strong></p>
<p>To use tab as a field separator you can use bash shell features when<br />
launching psql:</p>
<p>psql -A -t -U $DBUSER -d $DB -c &#8220;$QUERY&#8221; -F $&#8217;\t&#8217;</p>
<p>When you are already running psql, use this command:</p>
<p>\f&#8217;\t&#8217;</p>
<p>Apparently, using the single ticks (quotes) causes the \t to be<br />
evaluated by the shell&#8217;s command processor.</p>
<p>In order to get tab separated columns, you will also need to disable<br />
&#8220;aligned output&#8221; with \a.</p>
<p>Here is the entire sequence of commands:</p>
<p>\f&#8217;\t&#8217;<br />
\a<br />
\o myfile.txt<br />
select * from big_table;<br />
\o</p>
<p>I suspect that if you want true CSV output (comma separated with<br />
quoted fields, etc.) that you will need to write a small Perl script<br />
using a Perl CSV module, and using DBI to talk to Postgres. I&#8217;ve<br />
already got a Perl API which makes SQL even easier than DBI, so I<br />
could write the whole application in 10 lines of code.</p>
<p>The following does a date conversion from an integer containing the<br />
Unix timestamp, as well as truncating some columns for brevity and<br />
renaming other columns with long names. \H enables HTML output which<br />
in this case means a file with an HTML table (no &lt;HTML&gt; or &lt;BODY&gt;<br />
tags). This works fine in Firefox, but I haven&#8217;t tried it in othwer<br />
browsers. \o is send output to a file. Stop outputting with a blank \o.</p>
<p>\H<br />
\o public_html/summary.html<br />
select cl_pk,who_updated as who,plate,prow,pcol,substring(date &#8216;1970-01-01&#8242; + screen_date * interval &#8216;1 second&#8217; from &#8216;.*\ &#8216;) as scrn_date,comments,substring(gene_id from &#8216;^.{5}&#8217;)||&#8217;&#8230;&#8217; as gene,substring(sequence from &#8216;^.{5}&#8217;)||&#8217;&#8230;&#8217; as seq,image_file,localization as loc,morphology as morph,migration as mig,secretion as sec,is_valid as ok from clone order by cl_pk;</p>
<p>Here is the same query formatted:</p>
<p>SELECT cl_pk,<br />
who_updated AS who,<br />
plate,<br />
prow,<br />
pcol,<br />
SUBSTRING(DATE &#8216;1970-01-01&#8242; + screen_date * INTERVAL &#8216;1 SECOND&#8217; FROM &#8216;.*\ &#8216;) AS scrn_date,<br />
comments,<br />
SUBSTRING(gene_id FROM &#8216;^.{5}&#8217;)||&#8217;&#8230;&#8217; AS gene,<br />
SUBSTRING(sequence FROM &#8216;^.{5}&#8217;)||&#8217;&#8230;&#8217; AS seq,<br />
image_file,<br />
localization AS loc,<br />
morphology AS morph,<br />
migration AS mig,<br />
secretion AS sec,<br />
is_valid AS ok<br />
FROM clone ORDER BY cl_pk;</p>
<p>This query was run against a single table that looks like:</p>
<p>create table &#8220;clone&#8221;<br />
(<br />
&#8220;cl_pk&#8221; integer DEFAULT nextval(&#8217;pk_seq&#8217;::text) NOT NULL,<br />
&#8220;ec_fk&#8221; integer,        &#8212; foreign key to ec_pk in exp_condition<br />
&#8220;plate&#8221; varchar(128),   &#8212; plate name aka plate id<br />
&#8220;prow&#8221; varchar(128),    &#8212; plate row A-F<br />
&#8220;pcol&#8221; integer,         &#8212; place column 1-12<br />
&#8220;lab_book&#8221; varchar(256),<br />
&#8220;screen_date&#8221; integer,  &#8212; unix timestamp<br />
&#8220;userid&#8221; integer,       &#8212; us_pk from usersec table or it&#8217;s equivalent<br />
&#8220;clone_status&#8221; integer, &#8212; probably from the type table<br />
&#8220;gene_id&#8221; varchar(256),<br />
&#8220;sequence&#8221; text,<br />
&#8220;localization&#8221; integer, &#8212; from the type table<br />
&#8220;morphology&#8221; integer,   &#8212; from the type table<br />
&#8220;migration&#8221; integer,    &#8212; from the type table<br />
&#8220;secretion&#8221; boolean,<br />
&#8220;comments&#8221; text,<br />
&#8220;image_file&#8221; varchar(256),  &#8212; image file to display in web page<br />
&#8220;who_updated&#8221; varchar(256), &#8212; last userid to update<br />
&#8220;ip_address&#8221; varchar(128),  &#8212; ip address from which record was updated<br />
&#8220;original_image_file&#8221; varchar(256), &#8212; original uploaded image file<br />
is_valid integer DEFAULT 1 &#8212; one=valid, zero=invalid<br />
) without OIDs;</p>
<p><strong>Spend 10 more minutes and understand why PostgreSQL is better than Oracle</strong></p>
<p>The following list is not complete, and I&#8217;m not an Oracle expert. I&#8217;m<br />
facile with Postgres, but would not call myself a Postgres expert<br />
either. Therefore the following list may contain errors. My conclusion<br />
is unchanged: PostgreSQL is the best database.</p>
<p>- Postgres isn&#8217;t encumbered by licenses. You can install it as often<br />
as you like on as many computers as you like.</p>
<p>- Postgres is part of Fedora and therefore faster and easier to<br />
install.</p>
<p>- Postgres is much smaller than Oracle. Postgres is around 6MB. Oracle<br />
10g is over 200MB.</p>
<p>- The Postgres Perl DBD driver is part of Fedora. You&#8217;ll have to go to<br />
CPAN, download and install the Oracle DBD driver.</p>
<p>- Read the DBD documentation for the Oracle DBD driver. The docs are<br />
full of features that may or may not work. There are loads of<br />
warnings about various features. For whatever reason, the Postgres<br />
DBD driver seems simpler, more robust and more mature.</p>
<p>- Oracle doesn&#8217;t seem to provide a &#8220;native&#8221; Oracle supported DBD<br />
driver. It isn&#8217;t clear that Oracle supports the authors of the Perl<br />
DBD driver (maybe they do, maybe they don&#8217;t&#8230; I can&#8217;t tell).</p>
<p>- Postgres allows functions as default values for columns in<br />
tables. Oracle doesn&#8217;t.</p>
<p>- The Oracle command line, sqlplus, is a flaming pile of crap. It<br />
doesn&#8217;t have any cursor control support, the previous command buffer<br />
is barely accessible, and it is missing tab complete, is appears to<br />
have no way to cancel a command (i.e., no control-C). It looks like<br />
something from the 1970s when a user interface meant a teletype or<br />
card reader. Yes, there is a fancy web interface, but many types of<br />
system administration simply are not feasible via a GUI interface,<br />
especially a web interface.</p>
<p>- The PostgreSQL command line interface, psql, has fully functional<br />
editing, a command buffer, tab complete for commands, tables and<br />
columns, cancel (via control-C). It is wonderful.</p>
<p>- At the command line interface, Postgres has help for every<br />
command. Oracle doesn&#8217;t. In fact, Oracle&#8217;s sqlplus has no built-in<br />
help for any SQL commands.</p>
<p>- The standard record display from sqlplus is very crude, and<br />
difficult to read.</p>
<p>- Postgres has a &#8220;text&#8221; datatype which does not require a size<br />
specification. There is no performance penalty for using this data<br />
type. Oracle has LONG and a couple of types of BLOBs, each of which<br />
has several show-stopper limitations.</p>
<p>- Oracle can have only one LONG per table. Postgres can have as many<br />
TEXT fields per table as you like. Oracle apparently can have only<br />
one BLOB per table (perhaps including LONG). Postgres does not have<br />
this limitation.</p>
<p>- When Perl DBI does a fetchrow_hashref() from Oracle, the field names<br />
come back all uppercase. Postgres returns field names lowercase. I<br />
enter all my field names lower case since they are easier to type.</p>
<p>- Oracle&#8217;s sqlplus defaults to autocommit off. That&#8217;s fine but when<br />
you update a record from sqlplus, any other processes that are<br />
trying to update that record will be locked until you<br />
commit. Perhaps this is why PostgreSQL&#8217;s psql command line interface<br />
defaults to autocommit (actually, there isn&#8217;t even a setting for it)<br />
and if you want a non-autocommit transaction in psql, you use begin;<br />
command; commit; to explicitly create a transaction.</p>
<p>- Postgres psql has many commands that display and/or manage the<br />
database meta data. There is useful &#8220;help&#8221; for all these<br />
commands. If you wish, there is also a mode that displays the actual<br />
SQL code used to display/manage the meta data.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/44/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/44/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=44&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2008/05/19/start-using-postgresql-now%e2%80%a6/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>kuch shayari aapki nazar&#8230;</title>
		<link>http://irfanworld.wordpress.com/2008/05/18/kuch-shayari-aapki-nazar/</link>
		<comments>http://irfanworld.wordpress.com/2008/05/18/kuch-shayari-aapki-nazar/#comments</comments>
		<pubDate>Sun, 18 May 2008 02:23:10 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Shayari]]></category>

		<category><![CDATA[faakir]]></category>

		<category><![CDATA[sher]]></category>

		<category><![CDATA[sher-o-shayari]]></category>

		<category><![CDATA[sudarshan fakir]]></category>

		<category><![CDATA[urdu]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/?p=43</guid>
		<description><![CDATA[some of the best urdu shayari (i.e. poetry), I come across recently. Enjoy !]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Naa mohabbat, na dosti ke liye<br />
waqt rukta nahi kissi ke liye</p>
<p>Dil ko apne saza na de yoo.n hee<br />
Iss zamaane&#8217; be-rukhi ke liye</p>
<p>Kal jawaani ka hashr kya hoga<br />
sonch le aaj, do gadhi ke liye</p>
<p>Har koi pyaar doondhta hai yahan<br />
Apni tanha see zindagi ke liye</p>
<p>Waqt ke saath saath chalta rahe<br />
yeh hee behtar hai aadmi ke liye</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Teray Rang Rang<br />
Teray Rang Rang<br />
Yeh Rang Dhang<br />
Moula Rang Rang</p>
<p>Tunay Ata Kiya<br />
Mainay Bhula Diya<br />
Tunay Phir Say Diya<br />
Na Shukar Kia<br />
Tunay Aur Diya<br />
Deta Hi Gaya<br />
Mu Mod Diyay Daryaon Kay<br />
Menay Hawa Main Udna Seekh Liya<br />
Meri Agli Nazar Sitaaron Par<br />
Phir Bhi Main Teray Sahaaron Par</p>
<p>Teray Rang Rang<br />
Teray Rang Rang<br />
Yeh Rang Rang<br />
Teray Rang Rang</p>
<p>Main Jahan Bhi Jaaon Dunya Main<br />
Teray Jalway Meray Sang Sang</p>
<p>Teray Rang Rang<br />
Teray Rang Rang<br />
Teray Rang Rang<br />
Teray Rang Rang</p>
<p>Main Zaat Paat Mein Oonch Neech Mein Aur Firqon Mein Bata Huwa<br />
Jo Sachai Ko Dhundla Day Dil Esi Gard Say Atta Huwa<br />
Shikwa Nahin Jism Ki Matti Say Par Rooh Bhi Ab Betaab Nahin<br />
Teray Hukam Pay Chalna Aik Taraf Tera Naam Bhi Lena Yaad Nahin<br />
Kam Say Kam Mujhko Lota Day<br />
Woh Rooh Aur Jism Ki Jang Jang</p>
<p>Teray Rang Rang<br />
Teray Rang Rang<br />
Teray Rang Rang<br />
Teray Rang Rang</p>
<p>Main Jahan Bhi Jaaon Dunya Main<br />
Teray Jalway Meray Sang Sang</p>
<p>Way Bulleya Assan Marna Nahin<br />
Dor Peya Koi Hor<br />
Dor Peya Koi Hor<br />
Dor Peya Koi Hor</p>
<p>Na Main Maumin Wich Maseetan<br />
Na Main Wich Kufar Diyan Rayt Aan</p>
<p>Na Main Paakan wich Paleet Aan<br />
Na Main Moosa Na Firown</p>
<p>Ki Jaana&#8217;n Main Kon<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
safar to maine kiya tha warna,<br />
saare sazoan saaman uske the</p>
<p>mein to bus raazdaar tha uska,<br />
saare raaz uske the</p>
<p>woh dariya mein pyasa baitha tha,<br />
jabke samandar tamam uske the</p>
<p>woh dhup mein baitha hai chaaw dene ko,<br />
jabke darakht saare sayadaar uske the,</p>
<p>aur yu to bazahir logoan mein maine rizk baata tha,<br />
lekin darparda saare haath uske the,</p>
<p>maine kamaal bulandi pe jakar socha irfan,<br />
yeh to saare kamaal uske the,<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>E Khuda Aaj Ye Faisla Karde,<br />
Use Mera ya Mujhe Uska Karde.</p>
<p>Bahut Dukh Sahe He Maine,<br />
Koi Khusi Ab Toh Muqadar Karde.</p>
<p>Bahot Muskil Lagta Hai Usse Duur Rehna,<br />
Judai Ke Safar Ko Kum Karde.</p>
<p>Jitna Duur Chale Gaye Woh Mujhse,<br />
Use Utna Kareeb Karde.</p>
<p>Nahi Likha Agar Nasib Me Uska Naam,<br />
To Khatam Kar Ye Zindagi aur Mujhe FANAA Karde<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Kitni jaldi yeh mulakat guzar jati hai<br />
pyas bujhti nahi ke barsat guzar jati hai</p>
<p>Apni yaadon se keh do ke yun na aaya kare<br />
neend aati nahi aur raat guzar jati hai<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
aashiyane ki baat karate ho<br />
dil jalane ki baat karate ho</p>
<p>saari duniya ke ranj-o-gam de kar<br />
muskuraane ki baat karate ho</p>
<p>ham ko apani Khabar nahi yaaro<br />
tum zamaane ki baat karate ho</p>
<p>zikr meraa suna to chid ke kahaa<br />
kis diwane ki baat karate ho</p>
<p>hadasaa tha guzar gaya hoga<br />
kis ke jaane ki baat karate ho<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
apanii marzi se kaha apane safar ke ham hain<br />
ruKh havaon ka jidhar ka hai udhar ke ham hain</p>
<p>pahale har chiz thi apani magar ab lagataa hai<br />
apane hi ghar mein kisi dusare ghar ke ham hain</p>
<p>waqt ke saath hai mitti kaa safar sadiyon tak<br />
kisako malum kaha ke hain kidhar ke ham hain</p>
<p>chalte rahate hain ki chalna hai musafir ka nasiib<br />
sochte rahte hain ki kis rahaguzar ke ham hain<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
asar us ko zaraa nahi hota<br />
ranj raahat-fizaa nahi hotaa</p>
<p>tum hamaare kisi tarah na hue<br />
warana duniya mein kya nahi hota</p>
<p>narazgi se dam ruke to ruke<br />
main kisi se Khafa nahi hota</p>
<p>tum mere paas hote ho goyaa<br />
jab koi dusra nahi hota</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/43/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/43/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=43&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2008/05/18/kuch-shayari-aapki-nazar/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>Sybase iSQL ASE 11.5 drive</title>
		<link>http://irfanworld.wordpress.com/2007/09/05/sybase-isql-ase-115-drive/</link>
		<comments>http://irfanworld.wordpress.com/2007/09/05/sybase-isql-ase-115-drive/#comments</comments>
		<pubDate>Wed, 05 Sep 2007 16:25:03 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[connect PostgeSQL from Perl]]></category>

		<category><![CDATA[DB]]></category>

		<category><![CDATA[ilsq]]></category>

		<category><![CDATA[isql]]></category>

		<category><![CDATA[isql comand]]></category>

		<category><![CDATA[isql command tour]]></category>

		<category><![CDATA[isql help]]></category>

		<category><![CDATA[LINUX]]></category>

		<category><![CDATA[Opensource]]></category>

		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Post]]></category>

		<category><![CDATA[PostgreSQL]]></category>

		<category><![CDATA[PostgreSQL vs Oracle]]></category>

		<category><![CDATA[PSQL tricks]]></category>

		<category><![CDATA[sp_help]]></category>

		<category><![CDATA[sp_helpdb]]></category>

		<category><![CDATA[sybase]]></category>

		<category><![CDATA[sybase 11.5]]></category>

		<category><![CDATA[sybase isql]]></category>

		<category><![CDATA[Sybase iSQL ASE 11.5]]></category>

		<category><![CDATA[use DBNAME]]></category>

		<category><![CDATA[why PostgreSQL is better than Oracle]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/2007/09/05/sybase-isql-ase-115-drive/</guid>
		<description><![CDATA[COMMAND TOUR
Connect sybase from Linux console
isql -Hpiidb199:9794 -SNYQ_MWDATA -Umware_rw -DGE2
use DN_Name
go
select DB_Name
go 
sp_helpdb DB_Name
go shows this info
name,db_size,owner,dbid,created,status,device_fragments,size,usage,created,free kbytessp_help
go
It shows all the availble objects of following type
view, user table, triggers, system table, stored procedure
sp_help Table_Name
go
shows description of table i.e.
Column_name,Type,Length,Prec,Scale Nulls,Default_name,Rule_name,Access_Rule_name,Identity
set rowcount 2
select * from ge_company
go
Below query will display exactly 2 records from table
select * from dbo.ge_comapany [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="font-size:x-small;"><strong>COMMAND TOUR</strong></span></p>
<p><span style="font-size:x-small;">Connect sybase from Linux console<br />
isql -Hpiidb199:9794 -SNYQ_MWDATA -Umware_rw -DGE</span><span style="font-size:x-small;">2</span></p>
<p><span style="font-size:x-small;">use DN_Name<br />
go</span></p>
<p><span style="font-size:x-small;">select DB_Name<br />
go</span><span style="font-size:x-small;"> </span></p>
<p><span style="font-size:x-small;">sp_helpdb </span><span style="font-size:x-small;">DB_Name<br />
go</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;">shows this info<br />
name,db_size,owner,dbid,created,status,device_fragments,size,usage,created,free kbytes</span><span style="font-size:x-small;">sp_help<br />
go</span></p>
<div><span style="font-size:x-small;">It shows all the availble objects of following type<br />
view, user table, triggers, system table, stored procedure</span></div>
<p><span style="font-size:x-small;">sp_help Table_Name<br />
go</p>
<p>shows description of table i.e.<br />
Column_name,Type,Length,Prec,Scale Nulls,Default_name,Rule_name,Access_Rule_name,Identity</p>
<p>set rowcount 2<br />
select * from ge_company<br />
go</p>
<p>Below query will display exactly 2 records from table<br />
select * from dbo.ge_comapany where company_id = 766<br />
go</p>
<p>*Note table should be given with owner, here dbo is owner of ge_company</p>
<p>sp_helpindex ge_company<br />
go</p>
<p>This command will show you list of indexes available into ge_company table<br />
select name from sysobjects where name like &#8220;ge_%&#8221;</p>
<p>By default these tables will be created automatically when new database created<br />
1&gt; sp_help<br />
2&gt; go</p>
<p>Name Owner Object_type<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
syb_auto_db_extend_control dbo user table<br />
sysalternates dbo system table<br />
sysattributes dbo system table<br />
syscolumns dbo system table<br />
syscomments dbo system table<br />
sysconstraints dbo system table<br />
sysdepends dbo system table<br />
sysgams dbo system table<br />
sysindexes dbo system table<br />
sysjars dbo system table<br />
syskeys dbo system table<br />
syslogs dbo system table<br />
sysobjects dbo system table<br />
syspartitions dbo system table<br />
sysprocedures dbo system table<br />
sysprotects dbo system table<br />
sysqueryplans dbo system table<br />
sysreferences dbo system table<br />
sysroles dbo system table<br />
syssegments dbo system table<br />
sysstatistics dbo system table<br />
systabstats dbo system table<br />
systhresholds dbo system table<br />
systypes dbo system table<br />
sysusermessages dbo system table<br />
sysusers dbo system table<br />
sysxtypes dbo system table<br />
Some more tips of Sybase blocking handel</p>
<p>2&gt; sp_block<br />
3&gt; go</p>
<p>no process should be in Absolute blocking spid</p>
<p>spid hostname<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212; &#8212;&#8212;&#8212;-<br />
Absolute blocking spid is 537 piias1359<br />
Absolute blocking spid is 49 pi944c3n9<br />
Absolute blocking spid is 616 paias1186<br />
One login can play with these commands</p>
<p>Show login user information<br />
&gt; sp_displaylogin<br />
&gt; go</p>
<p>Suid: 3018<br />
Loginame: irfansh</p>
<p>Fullname:<br />
Default Database: env<br />
Default Language:<br />
Auto Login Script:<br />
Configured Authorization:<br />
Locked: NO<br />
Date of Last Password Change: Jun 14 2007 2:01PM<br />
Password expiration interval: 0<br />
Password expired: NO<br />
Minimum password length: 6<br />
Maximum failed logins: 0<br />
Current failed login attempts:<br />
Authenticate with: ANY<br />
(return status = 0)</p>
<p>To change logged in users password<br />
&gt;sp_password old_passwd, new_passwd<br />
&gt;go</p>
<p>Selecting data from Table: querys and functions<br />
&gt; select sum(salary) from emp_tbl<br />
&gt; go</p>
<p>Determining which table columns to join<br />
1&gt; sp_helpjoins ge2_group, ge2_group_apps<br />
2&gt; go</p>
<p>first_pair<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
group_id group_id</p>
<p>(1 row affected)<br />
(return status = 0)</p>
<p>To find a table’s referenced tables.<br />
1&gt; sp_helpconstraint<br />
2&gt; go</p>
<p><strong>Aggregate Function Result</strong></p>
<p>sum([all|distinct] expression) Total of the (distinct) values in the expression</p>
<p>avg([all|distinct] expression) Average of the (distinct) values in the expression</p>
<p>count([all|distinct] expression) Number of (distinct) non-null values in the expression</p>
<p>count(*) Number of selected rows</p>
<p>max(expression) Highest value in the expression</p>
<p>min(expression) Lowest value in the expression</p>
<p>count vs. count(*)</p>
<p>While count finds the number of non-null values in the expression, count(*)</p>
<p>finds the total number of rows in a table. This statement finds the total number of books:</p>
<p>Adaptive Server ignores any null values in the column on which the</p>
<p>aggregate function is operating for the purposes of the function (except</p>
<p>count(*), which includes them). If you have set ansinull to on, Adaptive</p>
<p>Server returns an error message whenever a null value is ignored. For</p>
<p>more information, see the set command in the Reference Manual.</p>
<p>Use the having clause to display or reject rows defined by the group by</p>
<p>clause. The having clause sets conditions for the group by clause in the</p>
<p>same way where sets conditions for the select clause, except where cannot</p>
<p>include aggregates, while having often does. This example is legal:</p>
<p>select title_id from titles where title_id like &#8220;PS%&#8221; having avg(price) &gt; $2.0</p>
<p>But this example is not:</p>
<p>select title_id from titles where avg(price) &gt; $20</p>
<p>How the having, group by, and where clauses interact</p>
<p>When you include the having, group by, and where clauses in a query, the</p>
<p>sequence in which each clause affects the rows determines the final</p>
<p>results:</p>
<p>• The where clause excludes rows that do not meet its search conditions.</p>
<p>• The group by clause collects the remaining rows into one group for each unique value in the group by expression.</p>
<p>• Aggregate functions specified in the select list calculate summary values for each group.</p>
<p>• The having clause excludes rows from the final results that do not meet its search conditions.</p>
<p>Sorting query results: the order by clause</p>
<p>The order by clause allows you to sort query results by one or more</p>
<p>columns, up to 31.</p>
<p><strong>How joins work</strong></p>
<p>When you join two or more tables, the columns being compared must have</p>
<p>similar values—that is, values using the same or similar datatypes.</p>
<p>There are several types of joins, such as equijoins, natural joins, and outer</p>
<p>joins. The most common join, the equijoin, is based on equality. The</p>
<p>following join finds the names of authors and publishers located in the</p>
<p>same city:</p>
<p>select au_fname, au_lname, pub_name</p>
<p>from authors, publishers</p>
<p>where authors.city = publishers.city</p>
<p>au_fname au_lname pub_name</p>
<p>&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Cheryl Carson Algodata Infosystems</p>
<p>Abraham Bennet Algodata Infosystems</p>
<p>(2 rows affected)</p>
<p>This earlier query is an example of an equijoin:</p>
<p>select *</p>
<p>from authors, publishers</p>
<p>where authors.city = publishers.city</p>
<p>In the results of that statement, the city column appears twice. By</p>
<p>definition, the results of an equijoin contain two identical columns.</p>
<p>Because there is usually no point in repeating the same information, one</p>
<p>of these columns can be eliminated by restating the query. The result is</p>
<p>called a natural join.</p>
<p>example of a natural join is:</p>
<p>select au_fname, au_lname, pub_name</p>
<p>from authors, publishers</p>
<p>where authors.city = publishers.city</p>
<p>Self-joins and correlation names</p>
<p>Joins that compare values within the same column of one table are called</p>
<p>self-joins. To distinguish the two roles in which the table appears, use</p>
<p>aliases, or correlation names.</p>
<p>select au1.au_fname, au1.au_lname,</p>
<p>au2.au_fname, au2.au_lname</p>
<p>from authors au1, authors au2</p>
<p>where au1.city = &#8220;Oakland&#8221; and au2.city = &#8220;Oakland&#8221;</p>
<p>and au1.state = &#8220;CA&#8221; and au2.state = &#8220;CA&#8221;</p>
<p>and au1.postalcode = au2.postalcode</p>
<p>Outer joins</p>
<p>Joins that include all rows, regardless of whether there is a matching row,</p>
<p>are called outer joins. Adaptive Server supports both left and right outer</p>
<p>joins. For example, the following query joins the titles and the titleauthor</p>
<p>tables on their title_id column:</p>
<p>select *</p>
<p>from titles, titleauthor</p>
<p>where titles.title_id *= titleauthor.title_id</p>
<p>Inner joins, in which the joined table includes only the rows of the</p>
<p>inner and outer tables that meet the conditions of the on clause.</p>
<p>Outer joins, in which the joined table includes all the rows from the</p>
<p>outer table whether or not they meet the conditions of the on clause.</p>
<p>SubQueries</p>
<p>this query finds the names of all the publishers who publish</p>
<p>business books:</p>
<p>select pub_name</p>
<p>from publishers</p>
<p>where exists</p>
<p>(select *</p>
<p>from titles</p>
<p>where pub_id = publishers.pub_id</p>
<p>and type = &#8220;business&#8221;)</p>
<p>pub_name</p>
<p>to find the names of publishers who do not publish business</p>
<p>books, the query is:</p>
<p>select pub_name</p>
<p>from publishers</p>
<p>where not exists</p>
<p>(select *</p>
<p>from titles</p>
<p>where pub_id = publishers.pub_id</p>
<p>and type = &#8220;business&#8221;)</p>
<p>Using and Creating Datatypes</p>
<p>Datatypes by</p>
<p>category Synonyms Range Bytes of storage</p>
<p>Exact numeric: integers</p>
<p>tinyint 0 to 255 (Negative numbers are not</p>
<p>permitted.)</p>
<p>1</p>
<p>smallint 215 -1 (32,767) to -215 (-32,768) 2</p>
<p>int integer 231 -1 (2,147,483,647) to</p>
<p>-231 (-2,147,483,648</p>
<p>4</p>
<p>Exact numeric: decimals</p>
<p>numeric (p, s) 1038 -1 to -1038 2 to 17</p>
<p>decimal (p, s) dec 1038 -1 to -1038 2 to 17</p>
<p>Approximate numeric</p>
<p>float (precision) machine dependent 4 for default precision &lt; 16,</p>
<p>8 for default precision &gt;= 16</p>
<p>double precision machine dependent 8</p>
<p>real machine dependent 4</p>
<p>Money</p>
<p>smallmoney 214,748.3647 to -214,748.3648 4</p>
<p>money 922,337,203,685,477.5807 to</p>
<p>-922,337,203,685,477.5808</p>
<p>8</p>
<p>Date/time</p>
<p>smalldatetime January 1, 1900 to June 6, 2079 4</p>
<p>datetime January 1, 1753 to December 31,</p>
<p>9999</p>
<p>8</p>
<p>Character</p>
<p>char(n) character pagesize n</p>
<p>varchar(n) character varying,</p>
<p>char varying</p>
<p>pagesize actual entry length</p>
<p>unichar Unicode character pagesize n * @@unicharsize</p>
<p>(@@unicharsize equals 2)</p>
<p>univarchar Unicode character</p>
<p>varying, char varying</p>
<p>pagesize actual number of characters *</p>
<p>@@unicharsize</p>
<p>nchar(n) national character,</p>
<p>national char</p>
<p>pagesize n * @@ncharsize</p>
<p>nvarchar(n) nchar varying,</p>
<p>national char varying,</p>
<p>national character</p>
<p>varying</p>
<p>pagesize @@ncharsize * number of</p>
<p>characters</p>
<p>text 231 -1 (2,147,483,647) bytes or fewer 0 when uninitialized;</p>
<p>multiple of 2K after</p>
<p>initialization</p>
<p>Binary</p>
<p>binary(n) pagesize n</p>
<p>varbinary(n) pagesize actual entry length</p>
<p>image 231 -1 (2,147,483,647) bytes or fewer 0 when uninitialized;</p>
<p>multiple of 2K after</p>
<p>initialization</p>
<p>Bit</p>
<p>bit 0 or 1 1 (one byte holds up to 8 bit</p>
<p>columns))</p>
<p>1&gt; select name, hierarchy from systypes order by hierarchy</p>
<p>2&gt; go</p>
<p>name hierarchy</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;</p>
<p>floatn 1</p>
<p>float 2</p>
<p>datetimn 3</p>
<p>datetime 4</p>
<p>real 5</p>
<p>numericn 6</p>
<p>numeric 7</p>
<p>decimaln 8</p>
<p>decimal 9</p>
<p>moneyn 10</p>
<p>money 11</p>
<p>smallmoney 12</p>
<p>smalldatetime 13</p>
<p>intn 14</p>
<p>int 15</p>
<p>smallint 16</p>
<p>tinyint 17</p>
<p>bit 18</p>
<p>univarchar 19</p>
<p>unichar 20</p>
<p>sysname 22</p>
<p>varchar 22</p>
<p>nvarchar 22</p>
<p>update_id 22</p>
<p>char 23</p>
<p>nchar 23</p>
<p>timestamp 24</p>
<p>varbinary 24</p>
<p>binary 25</p>
<p>text 26</p>
<p>image 27</p>
<p>date 28</p>
<p>time 29</p>
<p>daten 30</p>
<p>timen 31</p>
<p>extended type 99</p>
<p>(37 rows affected)</p>
<p>Creating user-defined datatypes</p>
<p>Here is the syntax for sp_addtype:</p>
<p>sp_addtype datatypename,</p>
<p>phystype [ (length) | (precision [, scale] ) ]</p>
<p>[, "identity" |nulltype]</p>
<p>Here is how tid was defined:</p>
<p>sp_addtype tid, &#8220;char(6)&#8221;, &#8220;not null&#8221;</p>
<p>Dropping a user-defined datatype</p>
<p>To drop a user-defined datatype, execute sp_droptype:</p>
<p>sp_droptype typename</p>
<p>Note You cannot drop a datatype that is already in use in any table.</p>
<p>Getting information about datatypes</p>
<p>sp_help money</p>
<p>What are databases and tables?</p>
<p>Adaptive Server database objects include:</p>
<p>• Tables</p>
<p>• Rules</p>
<p>• Defaults</p>
<p>• Stored procedures</p>
<p>• Triggers</p>
<p>• Views</p>
<p>• Referential integrity constraints</p>
<p>• Check integrity constraints</p>
<p>Single database can have 2 billion tables as per ASE 11.5</p>
<p>Indian Quotation Amount International Quotation</p>
<p>1 Lakh 100,000.00 100 Thousands</p>
<p>10 Lakhs 1,000,000.00 1 Million</p>
<p>1 Crore 10,000,000.00 10 Million</p>
<p>10 Crores 100,000,000.00 100 Million</p>
<p>100 Crores 1,000,000,000.00 1 Billion</p>
<p>You can create temporary tables either by preceding the table name in a</p>
<p>create table statement with a pound sign (#) or by specifying the name</p>
<p>prefix &#8220;tempdb..&#8221;</p>
<p>Temporary tables are created in the tempdb database.</p>
<p>There are two kinds of temporary tables:</p>
<p>Tables that can be shared among Adaptive Server sessions</p>
<p>create table tempdb..authors</p>
<p>(au_id char(11))</p>
<p>drop table tempdb..authors</p>
<p>Tables that are accessible only by the current Adaptive Server session</p>
<p>or procedure</p>
<p>create table #authors</p>
<p>(au_id char (11))</p>
<p>exists until the current session or procedure ends, or owner drops it.</p>
<p>rules on temporary tables</p>
<p>• You cannot create views on these tables.</p>
<p>• You cannot associate triggers with these tables.</p>
<p>• You cannot tell which session or procedure has created these tables.</p>
<p>*NOTE: These restrictions do not apply to shareable, temporary tables created in</p>
<p>tempdb.</p>
<p>IDENTITY</p>
<p>You define an IDENTITY column by specifying the keyword identity,</p>
<p>Example</p>
<p>create table sales_daily</p>
<p>(sale_id numeric(5,0) identity,</p>
<p>stor_id char(4) not null)</p>
<p>Column &#8217;sale_id&#8217; will be maintained by sybase server. Similar to MySQL auto_increment feture. A row can be uniquely identified by this key.</p>
<p>*NOTE:- Avoid using IDENTITY in production since some time server enters a value which might not be in order.</p>
<p>By default, Adaptive Server begins numbering rows with the value</p>
<p>1, and continues numbering rows consecutively as they are added. Some</p>
<p>activities, such as manual insertions, deletions, or transaction rollbacks,</p>
<p>and server shutdowns or failures, can create gaps in IDENTITY column</p>
<p>values. Adaptive Server provides several methods of controlling identity</p>
<p>gaps described in &#8220;Managing identity gaps in tables&#8221;</p>
<p>The IDENTITY column contains a unique ID number, generated by</p>
<p>Adaptive Server, for each row in a table.</p>
<p>Uniq VS Primary key</p>
<p>Both</p>
<p>constraints create unique indexes to enforce this data integrity. However, primary key constraints are more restrictive than unique constraints. Columns with primary key constraints cannot contain a NULL value.</p>
<p>definition of unique constraints in the SQL standards specifies that the column definition shall not allow null values.</p>
<p>sp_primarykey, sp_foreignkey, and sp_commonkey define the logical relationship of keys (in the syskeys table) for table columns, which you enforce by creating indexes and triggers</p>
<p>There can be only one clustered index on a table,</p>
<p>The maximum number of references allowed for a table is 192.</p>
<p>Using sp_helpconstraint to find a table’s constraint information</p>
<p>A schema is a collection of objects owned by a particular user, and the permissions associated with those objects.</p>
<p>example:</p>
<p>create schema authorization dbo</p>
<p>create table list1</p>
<p>(col_a char(10) primary key,</p>
<p>col_b char(10) null</p>
<p>references list2(col_A))</p>
<p>create table list2</p>
<p>(col_A char(10) primary key,</p>
<p>col_B char(10) null</p>
<p>references list1(col_a))</p>
<p>You can declare a check constraint to limit the values users insert into a column in a table.</p>
<p>example:</p>
<p>create table my_new_publishers</p>
<p>(pub_id char(4)</p>
<p>check (pub_id in (&#8221;1389&#8243;, &#8220;0736&#8243;, &#8220;0877&#8243;,</p>
<p>&#8220;1622&#8243;, &#8220;1756&#8243;)</p>
<p>or pub_id like &#8220;99[0-9][0-9]&#8220;),</p>
<p>pub_name varchar(40),</p>
<p>city varchar(20),</p>
<p>state char(2))</p>
<p>Create table from existing table using &#8220;select into&#8221;</p>
<p>example:</p>
<p>1&gt; select pname, sname into friends_name from froends_etc</p>
<p>2&gt; go</p>
<p>(0 rows affected)</p>
<p>Execution Time (ms.): 1000 Clock Time (ms.): 1000</p>
<p>View Limitation</p>
<p>There are a few restrictions on the select statements in a view definition:</p>
<p>• You cannot include order by or compute clauses.</p>
<p>• You cannot include the into keyword.</p>
<p>• You cannot reference a temporary table.</p>
<p>For example, to rename titleview to bookview, enter:</p>
<p>sp_rename titleview, bookview</p>
<p>Follow these conventions when renaming views:</p>
<p>To display the text of the create view statement, execute sp_helptext</p>
<p>example:</p>
<p>sp_helptext hiprice</p>
<p>&#8212;&#8212;&#8212;-</p>
<p>1</p>
<p>(1 row affected)</p>
<p>text</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>create view hiprice</p>
<p>as select *</p>
<p>from titles</p>
<p>where price &gt; $15 and advance &gt; $5000</p>
<p>(1 row affected, return status = 0)</p>
<p>sp_depends lists all the objects that the view or table references in the</p>
<p>current database, and all the objects that reference that view or table.</p>
<p>example:</p>
<p>sp_depends titles</p>
<p>Things inside the current database that reference</p>
<p>the object.</p>
<p>object type</p>
<p>&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>dbo.history_proc stored procedure</p>
<p>dbo.title_proc stored procedure</p>
<p>dbo.titleid_proc stored procedure</p>
<p>dbo.deltitle trigger</p>
<p>dbo.totalsales_trig trigger</p>
<p>dbo.accounts view</p>
<p>dbo.bookview view</p>
<p>dbo.categories view</p>
<p>dbo.hiprice view</p>
<p>dbo.multitable_view view</p>
<p>dbo.titleview view</p>
<p>(return status = 0)</p>
<p>sp_tables lists all views in a database when used in the following format:</p>
<p>sp_tables @table_type = &#8220;’VIEW’&#8221;</p>
<p> </p>
<p></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/40/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/40/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=40&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2007/09/05/sybase-isql-ase-115-drive/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>Call Me</title>
		<link>http://irfanworld.wordpress.com/2007/09/05/call-me/</link>
		<comments>http://irfanworld.wordpress.com/2007/09/05/call-me/#comments</comments>
		<pubDate>Wed, 05 Sep 2007 16:24:26 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Friends]]></category>

		<category><![CDATA[call]]></category>

		<category><![CDATA[call me]]></category>

		<category><![CDATA[irfan call]]></category>

		<category><![CDATA[Irfan Shaikh]]></category>

		<category><![CDATA[irfan shaikh call]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/2007/09/05/call-me/</guid>
		<description><![CDATA[
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.jaxtr.com/sirfan98cs?wtype=btn1&amp;sc=WordPress" target="_blank"><img src="http://www.jaxtr.com/user/img/icons/callmebutton.gif" border="0" alt="Call sirfan98cs from your phone!" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/41/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/41/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=41&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2007/09/05/call-me/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>

		<media:content url="http://www.jaxtr.com/user/img/icons/callmebutton.gif" medium="image">
			<media:title type="html">Call sirfan98cs from your phone!</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby Rocks :)</title>
		<link>http://irfanworld.wordpress.com/2007/07/18/ruby-rocks/</link>
		<comments>http://irfanworld.wordpress.com/2007/07/18/ruby-rocks/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 14:03:46 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[connect PostgeSQL from Perl]]></category>

		<category><![CDATA[DB]]></category>

		<category><![CDATA[LINUX]]></category>

		<category><![CDATA[Opensource]]></category>

		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Post]]></category>

		<category><![CDATA[PostgreSQL]]></category>

		<category><![CDATA[PostgreSQL vs Oracle]]></category>

		<category><![CDATA[PSQL tricks]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[why PostgreSQL is better than Oracle]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/2007/07/18/ruby-rocks/</guid>
		<description><![CDATA[Today I am going to share my very first experience with RubyOnRails, and to describe my feelings its fabulous.
Lets begin
What you need to know already?

You should be familiar with any MVC pattern
Should have knowledge of Ruby
Should know DB &#38; Web server fundamentals

I guess thats more then enough to begin rails journey.
To start with you need [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Today I am going to share my very first experience with RubyOnRails, and to describe my feelings its fabulous.</p>
<p>Lets begin</p>
<p>What you need to know already?</p>
<ul>
<li>You should be familiar with any MVC pattern</li>
<li>Should have knowledge of Ruby</li>
<li>Should know DB &amp; Web server fundamentals</li>
</ul>
<p>I guess thats more then enough to begin rails journey.</p>
<p>To start with you need following software installed on your box, <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I ma LILO fan so all below configuration and are Linux based. But based on this understanding one can quickly start writing on any other OS too.</p>
<p>Software Needed</p>
<ul>
<li>ruby 1.8.4</li>
<li>rails 1.2.3</li>
</ul>
<p>Once installation and configuration done</p>
<p>rails test_app</p>
<p>cd test_app</p>
<p>vi config/database.ym</p>
<p>add your db credential</p>
<p>script/generate migration add_formelements</p>
<p>&gt; create db/migrate<br />
&gt; create db/migrate/001_add_formelements.rb</p>
<p>vim db/migrate/001_add_formelements.rb</p>
<p>Add code<br />
<strong>class AddUsers &lt; ActiveRecord::Migration<br />
def self.up<br />
create_table &#8220;formelements&#8221; do |t|<br />
t.column &#8220;user&#8221;, :string<br />
t.column &#8220;email&#8221;, :string<br />
t.column &#8220;password&#8221;, :string<br />
t.column &#8220;passordreminder&#8221;, :text<br />
end<br />
end</strong></p>
<p><strong>def self.down<br />
drop_table &#8220;</strong><strong>formelements</strong><strong>&#8220;<br />
end<br />
end</strong></p>
<p>rake db:migrate</p>
<p>== AddUsers: migrating ========================================================<br />
&#8211; create_table(&#8221;formelements&#8221;)<br />
-&gt; 0.0234s<br />
== AddUsers: migrated (0.0236s) ===============================================</p>
<p>script/generate scaffold Formelement</p>
<p>exists app/controllers/<br />
exists app/helpers/<br />
exists app/views/formelements<br />
create app/views/layouts/<br />
create test/functional/<br />
dependency model<br />
create app/models/<br />
create test/unit/<br />
create test/fixtures/<br />
create app/models/formelement.rb<br />
create test/unit/formelement_test.rb<br />
create test/fixtures/formelement.yml<br />
identical app/views/formelements/_form.rhtml<br />
create app/views/formelements/list.rhtml<br />
create app/views/formelements/show.rhtml<br />
create app/views/formelements/new.rhtml<br />
create app/views/formelements/edit.rhtml<br />
create app/controllers/formelements_controller.rb<br />
create test/functional/formelements_controller_test.rb<br />
create app/helpers/formelements_helper.rb<br />
create app/views/layouts/formelements.rhtml<br />
create public/stylesheets/scaffold.css</p>
<p>script/server</p>
<p>http://yourserver3000/skills</p>
<p>That&#8217;s all enjoy!</p>
<p>Hope you have grate time doing above exercise.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/39/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/39/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=39&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2007/07/18/ruby-rocks/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>JAVA Design Pattern</title>
		<link>http://irfanworld.wordpress.com/2007/05/05/java-design-pattern/</link>
		<comments>http://irfanworld.wordpress.com/2007/05/05/java-design-pattern/#comments</comments>
		<pubDate>Sat, 05 May 2007 11:11:20 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[design pattern]]></category>

		<category><![CDATA[ejb]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[java architecht]]></category>

		<category><![CDATA[middelware]]></category>

		<category><![CDATA[RPC]]></category>

		<category><![CDATA[service-oriented architecture]]></category>

		<category><![CDATA[soap]]></category>

		<category><![CDATA[technology]]></category>

		<category><![CDATA[web services]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/2007/05/05/java-design-pattern/</guid>
		<description><![CDATA[JAVA Design Pattern
The design patten is a vast subject, I will be giving you an head start here
Gang of Four - widely used design patterns

Behavioral patterns

Chain of responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template method
Visitor


Creational patterns

Abstract factory
Builder
Factory method
Prototype
Singleton


Structural patterns

Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy



Definition:- Common Problem and Common Solution for them, If you have data with problem and to tackle that you need to find problem [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="text-decoration:underline;">JAVA Design Pattern</span></strong></p>
<p>The design patten is a vast subject, I will be giving you an head start here</p>
<p>Gang of Four - widely used design patterns</p>
<ol>
<li>Behavioral patterns
<ol>
<li>Chain of responsibility</li>
<li>Command</li>
<li>Interpreter</li>
<li>Iterator</li>
<li>Mediator</li>
<li>Memento</li>
<li>Observer</li>
<li>State</li>
<li>Strategy</li>
<li>Template method</li>
<li>Visitor</li>
</ol>
</li>
<li>Creational patterns
<ol>
<li>Abstract factory</li>
<li>Builder</li>
<li>Factory method</li>
<li>Prototype</li>
<li>Singleton</li>
</ol>
</li>
<li>Structural patterns
<ol>
<li>Adapter</li>
<li>Bridge</li>
<li>Composite</li>
<li>Decorator</li>
<li>Facade</li>
<li>Flyweight</li>
<li>Proxy</li>
</ol>
</li>
</ol>
<p>Definition:- Common Problem and Common Solution for them, If you have data with problem and to tackle that you need to find problem pattern and propose solution pattern for that.</p>
<p>Note: No body owns the design pattern</p>
<p>Standard pattern are 23 those are listed above.</p>
<p>J2EE design pattern standardize by sun</p>
<p>EJB Patterns</p>
<ol>
<li>Intercepting Filter (apache mod rewrite)</li>
<li>Composite View</li>
<li>Front Controller</li>
<li>Service to worker</li>
<li>Business delegate</li>
<li>Service Locater</li>
<li>Transfer object assembler</li>
<li>Facade</li>
</ol>
<p>site: theserverside.com<br />
site:www.tml.tkk.fi/~pnr/GoF-models/html</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/38/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/38/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=38&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2007/05/05/java-design-pattern/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>EJB cont</title>
		<link>http://irfanworld.wordpress.com/2007/05/05/ejb-cont/</link>
		<comments>http://irfanworld.wordpress.com/2007/05/05/ejb-cont/#comments</comments>
		<pubDate>Sat, 05 May 2007 07:44:23 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[ejb]]></category>

		<category><![CDATA[entity bean]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[java architecht]]></category>

		<category><![CDATA[middelware]]></category>

		<category><![CDATA[RPC]]></category>

		<category><![CDATA[service-oriented architecture]]></category>

		<category><![CDATA[session bean]]></category>

		<category><![CDATA[soap]]></category>

		<category><![CDATA[technology]]></category>

		<category><![CDATA[web services]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/2007/05/05/ejb-cont/</guid>
		<description><![CDATA[Entity Bean
An entity bean is representation of single row in a databases. Entity always be an heavy component. But the connectivity to database will be a transparent to developer. When you create a new entity bean automatically in database new row will be added.
ORM - Object Relational Mapping, row in a table will be one [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Entity Bean</strong></p>
<p>An entity bean is representation of single row in a databases. Entity always be an heavy component. But the connectivity to database will be a transparent to developer. When you create a new entity bean automatically in database new row will be added.</p>
<p>ORM - Object Relational Mapping, row in a table will be one object in memory.</p>
<p>Stateless Session Bean can have pooled creation.</p>
<p>Statefull Session Bean can have cached creation.</p>
<p>But Entity bean can have either cache or pooled creation.</p>
<p>Whenever you need to work with processed or in other words process matters over data you should use session bean. But whenever you want to work with DATA or in other words DATA matters over process you should use entity beans.</p>
<p>Entity beans are heavy object because its a in memory object for database table. Where each instance of entity bean object refer to one record set in table or row in table.</p>
<p>Entity beans are of two types<br />
Bean Managed Persistence<br />
Container Managed Persistence</p>
<p>CMP Bean<br />
Local Client<br />
Remote Client</p>
<p>Favourite topic WSAD entity bean example <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> without writing a single line of code get the entity bean in place here we go</p>
<ol>
<li>Create new project EntityBean</li>
<li>Create new Enterprise bean</li>
<li>Select Type Entity bean</li>
<li>Select CMP bean 2.0</li>
<li>Bean detail select Remote &amp; Local both the interfaces</li>
<li>Select the project</li>
<li>Run the Entity bean on server</li>
<li>Configure new Test Server or run on existing server</li>
<li>Create table and deploy entity bean</li>
<li>Finish</li>
<li>It will show success message, i.e. it will test the create and alter statement on newly created table.</li>
<li>Select server client local</li>
<li>Finish</li>
<li>It will open Test Client</li>
<li>Click on EntityExampleLocal</li>
<li>Click on CMPLocal.findByPrimaryKey</li>
<li>Enter value into and click invoke.</li>
</ol>
<p>This how you will be testing tyour entity beans. Just now what we have seen is the Top to Bottom appoch, we have another approach which is Bottom to Top where in we will be having table already existing in and then will be creating the entity bean accordingly.  </p>
<p>Facts&#8230;&#8230;&#8230;.</p>
<p>-EJB can be accessed using servlet<br />
-Entity Bean should not be remote<br />
-Session Bean should not be local<br />
-In entity bean you should not use primitive data-type.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/37/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/37/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanworld.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanworld.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanworld.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanworld.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanworld.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanworld.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanworld.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanworld.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanworld.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanworld.wordpress.com&blog=527174&post=37&subd=irfanworld&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanworld.wordpress.com/2007/05/05/ejb-cont/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/irfanworld-128.jpg" medium="image">
			<media:title type="html">irfan</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with perforce</title>
		<link>http://irfanworld.wordpress.com/2007/04/25/working-with-perforce/</link>
		<comments>http://irfanworld.wordpress.com/2007/04/25/working-with-perforce/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 09:22:04 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
		
		<category><![CDATA[Tech Book]]></category>

		<category><![CDATA[learn p4]]></category>

		<category><![CDATA[p4]]></category>

		<category><![CDATA[p4 commands]]></category>

		<category><![CDATA[p4 help]]></category>

		<category><![CDATA[p4 tutorials]]></category>

		<category><![CDATA[perforce]]></category>

		<category><![CDATA[version control]]></category>

		<category><![CDATA[Working with perforce]]></category>

		<guid isPermaLink="false">http://irfanworld.wordpress.com/2007/04/25/working-with-perforce/</guid>
		<description><![CDATA[If you are new to perforce you came to write place.
To access perforce repositories
You need perforce client
 
The following is a quick overview of the most common Perforce commands:
     p4 sync     - Sync up with the latest sources
     p4 edit     [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you are new to perforce you came to write place.</p>
<p>To access perforce repositories</p>
<p>You need perforce client</p>
<p> </p>
<p>The following is a quick overview of the most common Perforce commands:</p>
<pre>     p4 sync     - Sync up with the latest sources
     p4 edit     - Open a file for editing
     p4 add      - Add a new file to the repository
     p4 delete   - Delete a file from the repository
     p4 resolve  - Resolve conflicts if two people edit the same file
     p4 revert   - Revert changes for a currently opened file
     p4 submit   - Submit all changes to the repository
     p4 opened   - List all files you currently have opened</pre>
<p> </p>
<p> </p>
<p> </p>
<p>Even to change any single file you must have the entire code base check out.</p>
<p>set client view</p>
<p>cd respective folder</p>
<p>p4 sync</p>
<p>-edit Open an existing file for edit and commit<br />
[usage] p4 edit filename<br />
[usage] p4 submit</p>
<p>-filelog List revision history of files<br />
[usage] p4 filelog filename</p>
<p>-integrate Schedule integration from one file to another<br />
[usage] p4 integrate [FROM] [TO]<br />
*Nore both FROM and TO must be complete file path from //depo or //std on</p>
<p>-p4 have Lists all file revisions that the Perforce server knows you have in the client workspace.<br />
-p4 sync -n Reports what files would be updated in the client workspace by p4 sync without actually performing the sync operation</p>
<p><strong>Creating Branch</strong></p>
<p>p4 branch &lt;branch_name&gt;</p>
<ul>
<li>open p4 client</li>
<li>add view</li>
<li>//depot/from/&#8230; /depot/to/&#8230;</li>
</ul>
<p>p4 integrate -b &lt;branch_name&gt;<br />
p4 submit</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanworld.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanworld.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanworld.wordpre