file creation inside loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file creation inside loop
# 1  
Old 04-15-2009
file creation inside loop

i=1
while [ $i -lt 18 ]
do
touch TC$i.txt
i=`expr $1 + 1`
done
echo "files created successfully"

What is wrong with code...its running continuosly...
# 2  
Old 04-15-2009
plz help me....
# 3  
Old 04-15-2009
If you want only the change then that is

Code:
i=`expr $1 + 1`

to

Code:
i=`expr $i + 1`

---> notice it is not $1 it is $i

I assume you know shell scripting already, so am not giving any explanations...

Last edited by thegeek; 04-15-2009 at 04:11 AM.. Reason: inserting code tags to make it better understandble.
# 4  
Old 04-15-2009
Yes mate...u are correct

Now the script is working
# 5  
Old 04-15-2009
if you are on bash
Code:
touch TC{1..18}.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash directory loop and order by creation date?

Hello, how in bash i can get directory loop and order by creation date? THX! :) #!/bin/bash for folder in /home/test/* do if ; then echo $folder; fi (12 Replies)
Discussion started by: ZerO13
12 Replies

2. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies

3. Shell Programming and Scripting

Creating new file inside a for loop

Hi, I have list of files present in a folder. I want to search for a particular keyword sequentially and create a file which will be later used by some other program. Input files: $ ls a.dsx b.dsx c.dsx Dataline_.txt Dataline.txt loop.sh $ cat *.dsx help tyiis global for i in... (4 Replies)
Discussion started by: mac4rfree
4 Replies

4. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

5. Shell Programming and Scripting

File system creation script on AIX 6.1 using while loop

#!/bin/sh echo "VG: " read VG echo "LP: " read LP echo "SAP: " read SAP echo "NUM: " read NUM echo "SID: " read SID while ]; read VG LP SAP NUM SID ; do mklv -y $SAP$NUM -t jfs2 -e x $VG $LP; crfs -v jfs2 -d /dev/$SAP$NUM -m /oracle/$SID/$SAP$NUM ... (14 Replies)
Discussion started by: arorap
14 Replies

6. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

7. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

8. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

9. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

10. Shell Programming and Scripting

While loop password creation problem

#!/bin/bash #Filename: Assignment Author: Luke Francis quit=n while do clear echo "OPERATOR ADMINISTRATIVE TOOL" clear echo "1. User Information" echo "2. Network Connectivity" echo "3. Processes" echo "4. System Information" echo "5. Hardware Utilization" echo "Which option do you... (3 Replies)
Discussion started by: warlock129
3 Replies
Login or Register to Ask a Question