Solved

shell problem

Posted on 1997-05-30
2
335 Views
Last Modified: 2010-04-21
How can I use a numeric counter in a loop for in the shell
sh ?
0
Comment
Question by:jjescri
2 Comments
 

Author Comment

by:jjescri
ID: 2006342
Edited text of question
0
 
LVL 2

Accepted Solution

by:
mlev earned 10 total points
ID: 2006343
You cannot. The loop "for" only iterates on lists of values.
(Of course, for a small number of iterations, you can write a script that will generate a list
like "1 2 3 4 5 6 7 8 9 10" for you, but I don't think you are looking for something like this.)

If you are looking for an equivalent of, say,
for (i = 1; i <= 10; i++)
      do_something();

or

for i := 1 to 10 do
      do_something;

or whatever you are more comfortable with,
you can use the following structure:

i=1
while [ $i -le 10 ]
do
      do_something
      i=`expr $i + 1`
done

Manipulating numeric values is no much fun in Bourne shell...

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now