While Loop - stange error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While Loop - stange error
# 1  
Old 09-18-2008
While Loop - stange error

Hello

I am writing a script to copy files that contains a while loop to compare files that will do a cp -p until the filesizes are equal. I am getting a strange error though when the script gets to executing the while loop.

here is my code:

Code:
#/usr/bin/csh

#create the filename
echo "What is the name of the file you want created?"
set filename =<
touch $filename
#for some reason i had to touch the file 2 times to create it
touch $filename

#echo the filesize to make sure its 0 and that it was created
ls -l $filename | awk '{print $5}'

#ask the user what file they want copied
echo "what file do you want copied?" 
set filecopy =<

#ensure the filesize to be copied named as filecopy
ls -l $filecopy | awk '{print $5}'

while ["$filename" ne "filecopy"]
     do cp -p $filecopy $filename
        until "$filename" = "$filecopy"
endwhile

#do some math to give the user some sort of idea how far along we are
#to be implemented later

end

the error i get is missing ]

i have tried several different whiles, like this [while foo do something] and [[while foo do something ]] and quotes, no quotes around the variables as well as tick marks...

so here are my questions: 1. if i just used a file to compare against, is it possible that the while operation is messing up there? 2. i used the solaris scripting book and it said two brackets and quotes.

whatever assistance you can provide would be greatly appreciated.

Thanks!!

Joe
# 2  
Old 09-18-2008
1st:

should this:
Code:
while ["$filename" ne "filecopy"]

be this:
Code:
while ["$filename" -ne "$filecopy"]

# 3  
Old 09-18-2008
change your while loop to this..
Quote:
while [ "$filename" -ne "$filecopy" ]
# 4  
Old 09-18-2008
Code:
do cp -p $filecopy $filename
        until "$filename" = "$filecopy"

$filename would never = $filecopy if they didnt type the same name for both.
# 5  
Old 09-19-2008
Thanks, i found another error so i will re write it in the korn shell. I was also wanting to change it so that i am putting the cp -p in the background and performing some math operations to let the user know that their copy is still in progress.

and yes, it was not a direct copy and paste, so the errors that you all found were definitely errors.

Thanks for your inputs again! Happy scripting
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error in for loop

I was trying to implement a nested for do loop to run a perl script. for i in 1 10 50 do for j in 2 12 55 do perl script.pl "$i" "$i" "$j" done done when I implemented it within a shell script, i got the output, but every time j value will 55, or basically the last value of j in... (10 Replies)
Discussion started by: Kanja
10 Replies

2. Shell Programming and Scripting

Error in while loop

I have a file Table.out having table name like this Table_Emp Table_Exp Table_Fcr To show first 10 rows .. I' wrtng a script like this .. #!/bin/ksh cat /tmp/table.out|while read -r table vbar1 do <connect to db> then select * from $table limit 10; > /tmp/1.out done ... (3 Replies)
Discussion started by: netdbaind
3 Replies

3. Shell Programming and Scripting

Error with while loop

the program just prints all the command line arguments Getting error in the program error ./hellow: line 13: 0: command not found ./hellow: line 13: 0: command not found below is the program #!/bin/bash num=$# echo $num if then echo "No arguments are passed ." else ... (7 Replies)
Discussion started by: BHASKARREDDY006
7 Replies

4. Shell Programming and Scripting

Error Using an if Loop Within a While Loop

Hello All, I am having a problem with an “if loop” within a “while loop” in my Korn Shell program. The basic concept of the program is that it searches for the existence of a series of load files in a load directory, and once it finds one of these files, it begins the following process: · Creates... (4 Replies)
Discussion started by: jonesdk5
4 Replies

5. UNIX for Dummies Questions & Answers

error in for loop???

Hi, I get the following output 98 -1 98 0 ./get_AB04-time: line 79: ((: i< && 0 !=7 : syntax error: operand expected (error token is "&& 0 !=7 ") I have this part of code. Line 79 is the line of the for loop. echo ${OCCURRENCE} $i_START CASE=0; i_END=${i_START}... (4 Replies)
Discussion started by: f_o_555
4 Replies

6. Solaris

Error in while loop

Hi, Iam trying to add a while loop in my script in the below way which gets value from count file and checks if its not equal to 0.If yes then it shld echo me a message. while //count file has some number other than 0 do echo "count is not zero" done But iam getting this error:... (5 Replies)
Discussion started by: jyothi_wipro
5 Replies

7. IP Networking

netperf reslt TCP_RR TCP_STREAM is stange,help me

send byte=10 , I test two target, A and B different os. The TCP_STREAM' s result is higher than B but TCP_RR result is lower than B why? please help me (0 Replies)
Discussion started by: yanglei_fage
0 Replies

8. Shell Programming and Scripting

while loop error

while read line do echo "read line is $line" done < $file where $file is file having following contents 1=one 2=two 3=three but above while loop is not able to print last line !! why ? (3 Replies)
Discussion started by: crackthehit007
3 Replies

9. UNIX for Dummies Questions & Answers

Stange problem Dell PowerEdge 1950/ Boradcom Netextreme NIC

I have 2 Dell Poweredge 1950 servers running . I have been having intermittent performance issues with the NIC cards on one of them. The two servers are identical and are running the same operating system. The server that has the issue is on the DMZ on a a static IP and is hosting a website. ... (0 Replies)
Discussion started by: skotapal
0 Replies
Login or Register to Ask a Question