While loop error: Unexpected token done


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop error: Unexpected token done
# 8  
Old 04-13-2009
if [[ $line = *sometext* ]]; then

Missed the blanks around the [[ ]]...you can figure out the other stuff.
# 9  
Old 04-13-2009
Quote:
Originally Posted by sauron
Hi erenay,
i think you forgot a thousand of (") and(Smilie and spaces:

while read line do
if [[$line = *sometext*]] then echo $line fi
done < $FILENAME

must be:

while read line; do
if<space>[[<space>$line = *sometext*<space>]]; then echo "$line"; fi
done < $FILENAME

Bye
Thanks a lot sauron and giannicello. As you can see I'm a newbie.
I tried

#!/bin/sh
FILENAME=$1
while read line; do
if [[ $line = *sometext* ]]; then echo "$line"; fi
done < $FILENAME

and I still get the error:

line 5: syntax error near unexpected token `done'
line 5: `done < $FILENAME


I'll continue playing with it and update here if I can fix it. Thanks


Ohh my...
I was using cygwin and I used d2u for my txt file but not for my sh file. I thought it was OK since I was using vim to edit it. After using d2u for the .sh file too, it worked correctly.
Thanks again for the quick answers, I liked this community very much!

Last edited by erenay; 04-13-2009 at 04:46 PM..
# 10  
Old 04-13-2009
don't think Bourne shell likes the [[.

try this:

Code:
#!/bin/ksh

FILENAME=$1

if [ ! -f "$FILENAME" ]; then
  echo usage: $0 file_name
  exit 1
fi

while read line; do

  if [[ $line = *sometext* ]]; then
    echo "$line"
  fi

done < $FILENAME

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Syntax error near unexpected token 'do'

Hello all, Please i have this command i used to zip different files in differents directory, but i have an error. Note that when i run the command in one directory it works fine. /X5/WORK/BGH/INV/REG/pdf/SEND/BGH12523/1/*.fo /X5/WORK/BGH/INV/REG/pdf/SEND/BGH24523/1/*.fo... (3 Replies)
Discussion started by: gillesi
3 Replies

2. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hello every one!! I don't know where I am going wrong but I am finding it difficult to clear this error of syntax error near unexpected token `else' I am writing a simple shell script to find a file in a directory and if found execute that else return an error to the log file ... (14 Replies)
Discussion started by: masubram
14 Replies

3. Shell Programming and Scripting

For loop - unexpected token `do

My requirement is to search for current date-1 .log files in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs folder and write the file name to filenames.txt When I ran the script below, I got error as syntax error near unexpected token `do I'm not sure what is wrong in my code. I... (11 Replies)
Discussion started by: Ram Kumar_BE
11 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token `('

What do I do here? #!/bin/bash payload=-1 AND 1=IF(21,BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,112))),0)# hash=`echo -n $payload md5sum tr -d 'n' sed 'ss-sg' md5sum tr -d 'n' sed 'ss-sg'` curl --data cs2=chronopay&cs1=$payload&cs3=$hash&transaction_type=rebill... (2 Replies)
Discussion started by: iiiiiiiiiii
2 Replies

6. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

7. UNIX for Dummies Questions & Answers

Syntax error near unexpected token

hi! just want to seek help on this error: syntax error near unexpected token 'do this is my script # !/bin/sh # for y in 27 25 do exemmlmx -c "ZEEI;" -n XRT$y >> blah done what can be wrong? thanks! (6 Replies)
Discussion started by: engr.jay
6 Replies

8. Shell Programming and Scripting

Unexpected Token Error `;;'

Hello all, Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it. 7 ##******************************************************************************************************* 8 ## ********** FUNCTION USAGE *********** ... (13 Replies)
Discussion started by: raghunsi
13 Replies

9. Shell Programming and Scripting

Syntax error near unexpected token `done'

Hi all, Here is a simple script that is working in one server and is giving a syntax error in other server. Can somebody help me ? #!/bin/bash # ftp files done < $file errors: I tried..with no success: if ; then (21 Replies)
Discussion started by: Lenora2009
21 Replies

10. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies
Login or Register to Ask a Question