Looping advice


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping advice
# 1  
Old 12-24-2012
Looping advice

Hello guys


i am generating files in while loop and i want add value in every file start from 10 to 55 and repeat that

so the value never exceed 55 and always start from 10

can you advice how this can be done in while loop?
# 2  
Old 12-24-2012
Try
Code:
while true; do echo "$(( 10+i++%46 ))"; done

May not work in every shell, but should do in e.g. bash, ksh ...
# 3  
Old 12-25-2012
Quote:
Originally Posted by RudiC
Try
Code:
while true; do echo "$(( 10+i++%46 ))"; done

May not work in every shell, but should do in e.g. bash, ksh ...
hello

but this script run from 10 to 46 but not repeat again
# 4  
Old 12-25-2012
Code:
#!/bin/bash

counter=10

while true
do
        if [ $counter -eq 56 ]
        then
                counter=10
        fi

        echo $counter

        counter=$(( counter + 1 ))
done

# 5  
Old 12-25-2012
Quote:
Originally Posted by mogabr
hello
but this script run from 10 to 46 but not repeat again
So you might be using a shell not supporting the construct. With bash:
Code:
$ while true; do echo "$(( 10+i++%46 ))"; done
10
11
12
13
.
.
.
54
55
10
11
.
.
.
54
55
10
11
.
.
.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Advice

Guys, Can you tell me what value would additional knowledge of PERL and CGI scripting will add to my skill set of UNIX shell scripting and ORACLE PL/SQL? I understand that PERL is a good tool for text processing. (1 Reply)
Discussion started by: yabhi_22
1 Replies

2. Shell Programming and Scripting

Advice on script

Hi folks, I use following script:- #!/bin/sh # cd Linbread TODAY=`date +"%m%d"` DATA=`grep $TODAY linbread.dat` HOUR=`date +"%H"` if then TOD="Morning" elif then TOD="Afternoon" else TOD="Evening" fi echo $DATA | gawk -F"|" '{printf("%s\n\n%s",$2,$3)}' > $$tmp fold -s -w60... (0 Replies)
Discussion started by: satimis
0 Replies

3. Red Hat

Any advice would help

Hi everyone. I must admit up front that I am not very strong when it comes to Linux. I am actually a Windows guy, but don't let that count against me. :) I work for a very small company so we do not have a Server/Linux Admin on staff. Most of our needs have been handled by our WebHost. We have... (2 Replies)
Discussion started by: liquidstyleb
2 Replies

4. UNIX for Dummies Questions & Answers

need advice

i am currently running windows vista home premium, i want to install unix because i just started a computer programing course, i am just wondering if i install unix will i still have vista?? how does it work? will i get a choice of which os to run on system startup?? (1 Reply)
Discussion started by: naner9
1 Replies

5. Shell Programming and Scripting

Script Help/Advice

Alright, I feel like I have a pretty good basic knowledge of shell scripting, but this one is throwing me for a loop. I know I've seen something similar done with awk, but I couldn't find it with the search function. I've grepped through my log file and get results like this: --... (14 Replies)
Discussion started by: earnstaf
14 Replies

6. UNIX for Advanced & Expert Users

scripting advice

what is the good way to improve your skill in shell scripting?? (4 Replies)
Discussion started by: memphiz16
4 Replies

7. Shell Programming and Scripting

Script Advice please?

Ok. I want to parse a log file and search only for denied traffic for the previous hour. The log looks like this: Jun 18 17:47:56 routername 36806: Jun 18 17:53:01.088: %SEC-6-IPACCESSLOG: list ingress-filter denied tcp 1.2.3.4(1234) -> 6.7.8.9(53), 4 packets I only really care about the... (12 Replies)
Discussion started by: earnstaf
12 Replies

8. Shell Programming and Scripting

looking for advice...

Hi. First of all, Im an msoft guy, and when it comes to linux/unix, I'm retarded. Here is what I'm trying to do. I want to start I want to automatically connect to a remote server. Then I need it to login(https) -insert the licensce in the box(vi) -based on that licensce, the... (1 Reply)
Discussion started by: bravo24601
1 Replies

9. UNIX for Dummies Questions & Answers

Need advice: Awk vs something else?

I have a while read loop cycling through a fixed-length csv file and I'd like to use an if statement to check two fields in each line. I'm basically asking for your suggestions on the best and easiest way to check two fields in each line. I'm sure many of you may be thinking just use awk, but if... (1 Reply)
Discussion started by: yongho
1 Replies

10. UNIX Desktop Questions & Answers

Looking for some advice

I am looking for some advice on wether to use unix or red hat linux? I have played with most windows OS and Mac OS up to in and including OS X. any and all advice would be appreciated (4 Replies)
Discussion started by: justawind
4 Replies
Login or Register to Ask a Question