Posts

Showing posts from May, 2012

Playing with shell!

Playing with shell Here I have summarized few shell script which I routinely use. All the informations are floating in the net. It needs just a little bit of careful google search and then test by yourself. Start with a simple one: Addition, subtraction, multiplication and division  Let say a=10, b=5, c=a+b or a-b or a/b or a*b. How to do that using Bash (Born Again Shell) shell scripting? However, bash script will give result in integer number.    a=10 b=5 c=$(($a+$b)) echo $c It will print 15. c=$(($a-$b)) echo $c It will print 5. c=$(($a/$b)) echo $c It will print 2.   c=$(($a*$b)) echo $c It will print 50. Let say you would like to do little complex calculation like  c=(a+b)/a*10 - b/(a-100)   c=$(($(($a+$b))/$(($a*10))-$(($b/$(($a-100)))))) What if one needs to get the same operation for real numbers? One needs to use then awk script. a=10.5 b=2.5 c=$(echo $a $b | awk '{ print $1 + $2 }') echo