Friday, November 9, 2012

Shell: How to increment a value in a shell script

This is a very basic question that comes into our mind many times while writing a shell script.

Here is a small code that you may find it useful.

while [ $i -le $j ]
i=`expr $i + 1`
echo $i

Here I am using expr unix command. This command evaluates arguments as expressions. You can find more details about expr by typing man expr in your terminal or check this link for online manual.

No comments:

Post a Comment