Saturday, June 21, 2008
Posted by venu k
8 comments | 12:44 AM
Bash variables are defaults to global What makes a variable local? A variable declared as local is one that is visible only within the block of code in which it appears. It has local "scope." In a function, a local variable has meaning only within that function block.Ex:local variable name func (){local loc_var=23# Declared as local variable.# Uses the 'local' builtin.echo "\"loc_var\" in function = $loc_var"global_var=999 # Not declared as local.# Defaults to global.echo "\"global_var\" in function = $global_var"}func# Now, to see if local variable...
Posted by venu k
2 comments | 12:24 AM
Unlike many other programming languages, Bash does not separate its variables by "type". Essentially, Bash variables are character strings, but, depending on context, Bash permits integer operations and comparisons on variables. The determining factor is whether the value of a variable contains only digits.Integer or string?a=2334 # Integer.let "a += 1"echo "a = $a " # a = 2335 # Integer, still.b=${a/23/BB} # Substitute "BB" for "23". # This transforms $b into a string.echo...
Friday, June 6, 2008
Posted by venu k
4 comments | 7:56 AM
#!bin/bash# backs up all files in current directory modified within last 24 hours# in a tarred and zipped file# Replace 1 with how many day's you want to back up filesBACKUPFILE=backup-`date +"%m-%d-%Y"`# Embeds date in backup filenamearchive=${1:-$BACKUPFILE}#If no filename specified default to backup-MM-DD-YYYYfind . -mtime -1 -type f -print0 xargs -0 tar rvf "$archive.tar"#check bellow command# tar cvf - $(find . -mtime -1 -type f -print) > $archive.tar# It works But will fail to backup file names contain space# if there is no files containing...
Wednesday, June 4, 2008
Posted by venu k
7 comments | 6:11 AM
#!/bin/bash# Traverse a directory using depth first traversal technique# Usage $0 directorypath# otherwise it takes current working directory as directory pathdepth(){#Do a small depth checking how deep into the tree we are k=0 while [ $k -lt $1 ] do echo -n " " let k++ #or use k=`expr $k + 1` done}traverse(){# Traverse a directoryls "$1"while read ido depth $2 if [ -d "$1/$i" ] then echo Directory: $1/$i traverse "$1/$i" `expr $2 + 1` ...
Friday, April 25, 2008
Posted by venu k
14 comments | 10:02 PM

Small Chess Board#!/bin/bash# SCRIPT : smallchessboard.sh# PURPOSE : Prints small chess board on the screen.clearfor (( i=1 ; i<=8 ; i++ ))do for (( j=1 ; j<=8 ; j++ )) do if [ `expr $(($i+$j)) % 2` -eq 0 ] then echo -e -n "\033[47m " # White background else echo -e -n "\033[40m " # Black background fi done echo # move to next linedoneecho -e "\033[0m" ...
Tuesday, April 1, 2008
Posted by venu k
3 comments | 10:51 PM
time head -5 emp.lst tail -1It has taken time for execution isreal 0m0.004suser 0m0.001ssys 0m0.001sorawk 'NR==5' emp.lstIt has taken time for execution isreal 0m0.003suser 0m0.000ssys 0m0.002sor sed -n '5p' emp.lstIt has taken time for execution isreal 0m0.001suser 0m0.000ssys 0m0.001sor using some cute trick we can get this with cut commandcut -d ““ -f 5 emp.lst# after -d press enter ,it means delimiter is newlineIt has taken time for execution isreal 0m0.001suser 0m0.000ssys 0m0.001sAnalysis: comparing above commands 'head' command taken maximum...
Posted by venu k
6 comments | 1:50 AM
· Resource-intensive tasks, especially where speed is a factor (sorting, hashing,etc.)Procedures involving heavy-duty math operations, especially floatingpoint arithmetic, arbitraryprecision calculations, or complex numbers(use C++ or FORTRAN instead)· Cross-platform portability required (use C or Java instead) Complex applications, where structured programming is a necessity (need type-checking of variables, function prototypes, etc.)· Project consists of subcomponents with interlocking dependencies Extensive file operations required (Bash is...
Monday, March 31, 2008
Posted by venu k
6 comments | 10:57 PM
No programming language is perfect. There is not even a single best language; there areOnly languages well suited or perhaps poorly suited for particular purposes. -- UNIX is simple. But It just needs a genius to understand its simplicity. --Dennis Ritchie We will be using Bash, an acronym for "Bourne--Again shell" developed by Brian Fox and...
Subscribe to:
Posts (Atom)