The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
for loop sytax error Rajat UNIX for Dummies Questions & Answers 3 07-02-2008 10:39 AM
syntax error in while loop habzone2007 Shell Programming and Scripting 1 05-18-2008 04:31 PM
Stange problem Dell PowerEdge 1950/ Boradcom Netextreme NIC skotapal UNIX for Dummies Questions & Answers 0 10-17-2007 02:50 PM
Unix-Sql Loop error manu_byc Shell Programming and Scripting 3 02-05-2007 09:40 AM
Error in for loop? hugow UNIX for Dummies Questions & Answers 3 06-28-2005 03:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-18-2008
caddyjoe77 caddyjoe77 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 40
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 (permalink)  
Old 09-18-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
1st:

should this:
Code:
while ["$filename" ne "filecopy"]
be this:
Code:
while ["$filename" -ne "$filecopy"]
  #3 (permalink)  
Old 09-18-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
change your while loop to this..
Quote:
while [ "$filename" -ne "$filecopy" ]
  #4 (permalink)  
Old 09-18-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Code:
do cp -p $filecopy $filename
        until "$filename" = "$filecopy"
$filename would never = $filecopy if they didnt type the same name for both.
  #5 (permalink)  
Old 09-19-2008
caddyjoe77 caddyjoe77 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 40
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0