Solved

shell problem

Posted on 1997-05-30
2
345 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
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.

756 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