Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

shell problem

Posted on 1997-05-30
2
Medium Priority
?
350 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 40 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

971 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