• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Wednesday, October 7, 2009

Posted by venu k
1 comment | 7:58 AM
A 'for loop' is a bash programming language statement which allows code to be repeatedly
executed. A for loop is classified as an iteration statement i.e. it is the repetition of a process
within a bash script.

For example, you can run UNIX command or task 5 times or read and process list of files using
a for loop. A for loop can be used at a shell prompt or within a shell script itself.

for loop syntax
Numeric ranges for syntax is as follows:

for VARIABLE in 1 2 3 4 5 .. N
do
command1
command2
commandN
done

Examples:
#!/bin/bah
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done

Using “seq” command

#!/bin/bash
for i in $(seq 1 2 20)
do
echo "Welcome $i times"
done

To know more about “seq” command check manual using “man seq” command

Bash 3.0+ version supports following syntax also

#!/bin/bash
for i in {1..5}
do
echo "Welcome $i times"
done

Three expression syntax

for (( EXP1; EXP2; EXP3 ))
do
command1
command2
command3
done

Example:
#!/bin/bash
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..." done

1 comment: