If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Error with a variable and a loop

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-05, 14:14
coreycollins coreycollins is offline
Registered User
 
Join Date: Feb 2005
Posts: 1
Error with a variable and a loop

I'm writing a basic shell script to just read a file from the bottom line up. It will read each line, line by line then it will execute the line from the file. I currently am just trying to have it print out each line and I am getting an error running my program.

I am getting an error on line 5 which is my while loop like. My count value is currently 306 and I get an error saying: ./rebuildall.sh[5]: 306: not found.

Any ideas. My code is below. I know I am missing something simple.

Thank you

Code:
#!/bin/sh                               
#echo $1                                
count=`wc -l test.out | cut -c1-8`      
count=`expr $count + 0`                 
while ($count >= 0)                     
do                                      
  #echo $file_length                    
  line=`head -$count test.out | tail -1`
  echo $line                            
  count = `expr $count - 1`             
done
Reply With Quote
  #2 (permalink)  
Old 02-09-05, 14:26
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
I think it should be like this:

Code:
while [ "$count" -ge "0" ] ;
Also, don't leave spaces between "count", "=", and "`expr..."
Reply With Quote
  #3 (permalink)  
Old 02-09-05, 14:45
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
also..... a bit different approach - reversing the file 'in-place':

sed -n '1!G;h;$p' test.out
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #4 (permalink)  
Old 02-09-05, 17:49
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Quote:
Originally Posted by vgersh99
sed -n '1!G;h;$p' test.out
Nice trick! May end up with the stack overflow with a large file though.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On