Sunday, December 26, 2010
Posted by venu k
311 comments | 7:36 AM
One thing that often confuses new users to the Unix / Linux shell, ishow to do (even very simple) maths. In most languages, x = x + 1 (oreven x++) does exactly what you would expect. The Unix/Linux shell isdifferent,however. It doesn’t have any built-in mathematical operatorsfor variables. It can do comparisons, but maths isn’t supported, noteven simple addition. Shell script variables are by default treated as strings,not numbers,which adds some complexity to doing math in shell script. To keep withscript programming paradigm and allow for better...
Wednesday, December 22, 2010
Posted by venu k
39 comments | 12:38 PM
By definition in mathematics, the Fibonacci Numbers are the numbersin the below sequence:0,1,1,2,3,5,8,13,21,34,55,89,144, ...... By definition, the first two Fibonacci numbers are 0 and 1, and eachsubsequent number is the sum of the previous two. Some sources omitthe initial 0, instead beginning the sequence with two 1s. In mathematical terms, the sequence Fn of Fibonacci numbers is defi-ned by the recurrence relation Fn = Fn-1 + Fn-2,with seed values F0 = 0 and F1 = 1.Iterative Method: #!/bin/bash#!/bin/bash# SCRIPT: fibo_iterative.sh#...
Monday, December 20, 2010
Posted by venu k
16 comments | 12:08 PM
#!/bin/bash# SCRIPT: armstrong_bw_range.sh# USAGE: armstrong_bw_range.sh# PURPOSE: Finding Armstrong numbers between given range.# \\\\ ////# \\ - - //# @ @# ---oOOo-( )-oOOo---#Armstrong numbers are the sum of their own digits to the power of#the number of digits. As that is a slightly brief wording, let me#give an example:#153 = 1³ + 5³ + 3³#Each digit is raised to the power three because 153 has three#digits. They are totalled and we get the original...
Posted by venu k
20 comments | 12:00 PM
#!/bin/bash# SCRIPT: armstrongnumber.sh# USAGE: armstrongnumber.sh# PURPOSE: Check if the given number is Armstrong number ?# \\\\ ////# \\ - - //# @ @# ---oOOo-( )-oOOo---# Armstrong numbers are the sum of their own digits to the power of# the number of digits. As that is a slightly brief wording, let me# give an example:# 153 = 1³ + 5³ + 3³# Each digit is raised to the power three because 153 has three# digits. They are totalled and we get the original...
Posted by venu k
10 comments | 6:28 AM
#!/bin/bash# SCRIPT: dec2binary.sh# USAGE: dec2binary.sh Decimal_Number(s)# PURPOSE: Decimal to Binary Conversion. Takes input as command line# arguments.# \\\\ ////# \\ - - //# @ @# ---oOOo-( )-oOOo---####################################################################### Script Starts Here ######################################################################if [ $# -eq 0 ]then echo "Argument(s)...
Posted by venu k
10 comments | 6:22 AM
#!/bin/bash# SCRIPT: binary2dec.sh# USAGE: binary2dec.sh Binary_Numbers(s)# PURPOSE: Binary to Decimal Conversion. Takes input as command line# arguments.# \\\\ ////# \\ - - //# @ @# ---oOOo-( )-oOOo---####################################################################### Script Starts Here ######################################################################if [ $# -eq 0 ]then echo "Argument(s)...
Sunday, December 19, 2010
Posted by venu k
82 comments | 11:25 AM
Method 1:#!/bin/bash# SCRIPT: validinteger.sh# USAGE: validinteger.sh [ Input value to be validated ]# PURPOSE: validate integer input, allow negative integers also## \\\\ ////# \\ - - //# @ @# ---oOOo-( )-oOOo---## Using the $? exit status variable or integer comparison operators, a# script may test if a parameter contains only digits, so it can be# treated as an integer.####################################################################### Arguments Checking ...
Saturday, July 31, 2010
Posted by venu k
14 comments | 4:18 PM
Palindrome: A palindrome is a word, phrase, number or other sequenceof units that can be read the same way in either direction (the adjus-tment of punctuation and spaces between words is generally permitted).Examples: Phrases: Dammit, I'm mad!Quotations: Able was I ere I saw Elba. Madam, I'm Adam.Names: Some people have names that are palindromes.Lon Nol (1913- 1985) was Prime Minister of Cambodia. Palindromic names are very common in Finland. Examples include Emma Lamme,Sanna Rannas, Anni Linna...
Thursday, July 29, 2010
Posted by venu k
7 comments | 9:34 AM
#!/bin/bash#!/bin/bash# SCRIPT: insertionsort.sh## LOGIC: Here, sorting takes place by inserting a particular element# at the appropriate position, that’s why the name insertion sorting.# In the First iteration, second element ARRAY[1] is compared with# the first element ARRAY[0]. In the second iteration third element# is compared with first and second element. In general, in every# iteration an element is compared with all the elements before it.# While comparing if it is found that the element can be inserted at# a suitable position, then space...
Posted by venu k
9 comments | 9:29 AM
#!/bin/bash#!/bin/bash# SCRIPT: selectionsort.sh## LOGIC : Here, to sort the data in ascending order, the first element# ARRAY[0] is compared with all the other elements till the end of the# array. If it is greater than any other the elements then they are# interchanged. So after the first iteration of the outer for loop# smallest element will be placed at the first position. The same pro-# cedure is repeated for the other elements too.####################################################################### Define Functions...
Posted by venu k
14 comments | 9:23 AM
#!/bin/bash# SCRIPT: bubblesort.sh# LOGIC:# Bubble sort is a simple sorting, it works by repeatedly stepping# through the list to be sorted, comparing two items at a time and# swapping them if they are in the wrong order. If you are sorting# the data in Ascending order, at the end of the first pass, the# "heaviest" element has move to bottom. In the second pass, the# comparisons are made till the last but one position and now second# largest element is placed at the last but one position. And so# forth.#######################################################################...
Friday, May 14, 2010
Posted by venu k
68 comments | 11:45 PM

There are many ways to handle any task on a Unix platform, but some
techniques that are used to process a file waste a lot of CPU time.
Most of the wasted time is spent in unnecessary variable assignment and
continuously opening and closing the same file over and over. Using a
pipe also has a negative impact on the timing.
In this article I will explain various techniques for parsing a file
line by line. Some techniques are very fast and...
Tuesday, April 20, 2010
Posted by venu k
24 comments | 6:05 AM
Using tput command:#!/bin/bash# SCRIPT: digclock.sh# USAGE: ./digiclock &# PURPOSE: Displays time and date in the top right corner of the# screen using tput command.# To stop this digclock use command "kill pid"####################################################################################### VARIABLE DECLARATION ################### # To place the clock on the appropriate column, subtract the # length of $Time and $Date, which...
Sunday, April 18, 2010
Posted by venu k
12 comments | 8:19 AM
Using ANSI escape sequences : ANSI escape sequences or tput allow you to move the cursor around thescreen at will. This is more useful for full screen user interfacesgenerated by shell scripts, but can also be used in prompts.The movement escape sequences are as follows: - Position the Cursor: \033[<L>;<C>H Or \033[<L>;<C>f puts the cursor at line L and column C. - Move the cursor up N lines: \033[<N>A - Move the cursor down N lines: \033[<N>B...
Sunday, March 28, 2010
Posted by venu k
6 comments | 11:26 AM
To understand this article you should to be familiar with Linux adva-nced file permissions, otherwise go throw bellow link before followingthis article.Advanced File PermissionsMy Obejective: I have a folder which I want to share with "rw" permissions for aselected group of users. Let's say the folder is /home/project and Iwant to share it with the group development. What I want is not onlyhaving users accessing files in /home/project with rw access, but alsoto ensure that all files created in /home/project will have ownershipusername:development...
Saturday, March 27, 2010
Posted by venu k
84 comments | 10:51 AM
After you have worked for a while with Linux you discover probablythat there is much more to file permissions than just the "rwx" bits.When you look around in your file system you will see "s" and "t"$ ls -ld /tmpdrwxrwxrwt 29 root root 36864 Mar 21 19:49 /tmp$ which passwd/usr/bin/passwd$ ls -l /usr/bin/passwd-rwsr-xr-x 1 root root 22984 Jan 6 2007 /usr/bin/passwd What is this "s" and "t" bit? The vector of permission bits is really4 * 3 bits long. Yes there are 12 permission bits,not just 9.The firstthree bits are special and are frequently...
Subscribe to:
Posts (Atom)