Solved

shell problem

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
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 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.

832 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