The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 07:16 AM
"syntax error at line 21 :'done' unexpected." error message" ibroxy Shell Programming and Scripting 3 08-08-2007 03:45 AM
syntax error at line 59: `end of file' unexpected Remi SUN Solaris 4 01-16-2007 10:48 AM
syntax error at line 33: `elif` unexpected hazy UNIX for Dummies Questions & Answers 4 02-09-2006 10:51 AM
sh: syntax error at line 1: `>' unexpected atiato High Level Programming 2 03-16-2004 03:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-10-2006
Registered User
 

Join Date: Mar 2006
Posts: 1
for loop not working - syntax error at line 6: `end of file' unexpected

I have a file called test.dat which contains

a b

I have written a shell script called test.sh

for i in `cat test.dat`
do
echo $i
done

When i run this script using

sh test.sh

I get this message -

test.sh: syntax error at line 6: `end of file' unexpected

What is the problem.

Thanks,
Debojyoty
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-10-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Your script works fine for me. Open the script in vi and enter the command :set list to see if you have any characters mucking up your script.
Reply With Quote
  #3 (permalink)  
Old 03-10-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
It also occurred to me that one of you back ticks could be a single quote as well, which would certainly cause your error.

Code:
for i in `cat test.dat' <=== single quote and not back tick
do
echo $i
done

$ sh test.sh
test.sh: syntax error at line 5: `end of file' unexpected
Code:
for i in `cat test.dat` <=== back tick
do
echo $i
done

$ sh test.sh
a
b
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0