Pages

Wednesday, December 12, 2012

Linux Shell Scripting - Variable Declaration, Incrementing

Linux Shell Scripting - Variable Declaration, Incrementing,Looping

Variable Declaration - Integer

To assign an int value to a variable,

((j=1))

Variable Incrementing 

To Increment value to the variable,

 let j+=1
echo $j

Reference:



Looping using for loop

We can  Java syntax like (for loop) in shell script.
See the following block of script.

for ((i=1;i<10;i++))
 do
 echo $i;
 done
This syntax some what easy, when we want to iterate for longer time.

The same could be achieved by following block of script.

 for i in 1 2 3 4 5 6 7 8 9 10;
 do
 echo  $i
                                                     done
 
We cannot use this syntax,when we want to iterate  more number of times.




No comments:

Post a Comment