Solved

shell problem

Posted on 1997-05-30
2
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.
Suggested Courses

626 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