Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'
# 1  
Data Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'

first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good.

I appreciate some explanation or quick tips/suggestions...

Thanks!

SmilieNon-working, unable to finish/execute script below:Smilie
Code:
#[localuser@localhost ~]$ cat wk7.sh
      1 #!/bin/bash
      2 
      3 #Read tabc.txt
      4 tabc="cat tabc.txt"
      5 
      6 #Make week 7 assignment directory
      7 wk7dir=~/"wk7dir"
      8 
      9 #Prevents duplicates and errors
     10 if [ ! -d $wk7dir ]; then
     11 mkdir $wk7dir
     12 fi
     13 
     14 #Assign appropriate variables from tabc.txt
     15 $tabc | sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\(.\{8\}\).*$/\3 \5 \6 \7 \8/' | while read fileuser filesize filedate filename; sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\(.\{8\}\).*$/\7/' tabc.txt | sed 's/://' | while read filetime; do
     16 
     17 #Change filesize
     18 dd if=/dev/zero of=$wk7dir/$filename bs=$filesize count=1
     19 
     20 #Create files based on date and filename
     21 touch -d $filedate $wk7dir/$filename
     22 
     23 #Changes file permissions to allow read, write, and execute to all users
     24 find ~/"wk7dir" -type f -exec chmod 755 {} \;;
     25 
     26 ls -lR --time-style="+%Y%m%d" "wk7dir" | sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\)/\6/' | while read filedatestamp
     27 
     28 #Modify file time
     29 touch -mt $filedatestamp$filetime $wk7dir/$filename
     30 
     31 done
~                                                                                                                                          ===
 
:(::SEE ERROR OUTPUT BELOW:::wall:
 
[localuser@localhost ~]$ ./wk7.sh
./wk7.sh: line 31: syntax error near unexpected token `done'
./wk7.sh: line 31: `done'


Last edited by wolf@=NK; 06-13-2012 at 05:24 AM..
# 2  
Quote:
Originally Posted by wolf@=NK
first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good.

There is (at least) one syntax error in your script. Look at the following, quoted from your post:

Code:
#[localuser@localhost ~]$ cat wk7.sh
!/bin/bash
#Read tabc.txt
tabc="cat tabc.txt"
wk7dir=~/"wk7dir"
#Prevents duplicates and errors
if [ ! -d $wk7dir ]; then
mkdir $wk7dir
fi
#Assign appropriate variables from tabc.txt
$tabc | sed -e '<statement>' |\
while read fileuser filesize filedate filename; 
     sed -e '<statement' tabc.txt |\
     sed 's/://' |\
     while read filetime; do
          #Change filesize
          dd if=/dev/zero of=$wk7dir/$filename bs=$filesize count=1
          #Create files based on date and filename
          touch -d $filedate $wk7dir/$filename
          #Changes file permissions to allow read, write, and execute to all users
          find ~/"wk7dir" -type f -exec chmod 755 {} \;
          ls -lR --time-style="+%Y%m%d" "wk7dir" |\
          sed -e '<statement>' |\
          while read filedatestamp
               #Modify file time
               touch -mt $filedatestamp$filetime $wk7dir/$filename
          done


After the first and the third line the "do" is missing and some while-loops are not closed.

It pays usually to break up lines and indent properly. Most problems will become easier to track this way.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
pretty much I did the indentation and close the while-loops using the "\" forward slash However, I still get the same error?

Code:
[localuser@localhost ~]$ ./wk7.sh ./wk7.sh: line 37: syntax error near unexpected token `done' ./wk7.sh: line 37: `done'

and you mentioned I am missing do argument after the first and third line? may you correct or point out which line or where it is exactly since I've done some revisions yet still has an error...

Code:
1 #!/bin/bash #INSERT DO ARGUMENT HERE??? 2 3 #Read tabc.txt #INSERT DO ARGUMENT HERE??? 4 tabc="cat tabc.txt" 5 6 #Make week 7 assignment directory 7 wk7dir=~/"wk7dir" 8 9 #Prevents duplicates and errors 10 if [ ! -d $wk7dir ]; then 11 mkdir $wk7dir 12 fi 13 14 #Assign appropriate variables from tabc.txt 15 $tabc | sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\(.\{8\}\).*$/\3 \5 \6 \7 \8/' |\ 16 while read fileuser filesize filedate filename; 17 $tabc | sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\(.\{8\}\).*$/\7/' |\ 18 sed 's/://'|\ 19 while read filetime; do 20 21 #Change filesize 22 dd if=/dev/zero of=$wk7dir/$filename bs=$filesize count=1 23 24 #Create files based on date and filename 25 touch -d $filedate $wk7dir/$filename 26 27 #Changes file permissions to allow read, write, and execute to all users 28 find ~/"wk7dir" -type f -exec chmod 755 {} \; 29 30 ls -lR --time-style="+%Y%m%d" "wk7dir" |\ 31 sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\)/\6/' |\ 32 while read filedatestamp 33 34 #Modify file time 35 touch -mt $filedatestamp$filetime $wk7dir/$filename 36 37 done ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ :set number

---------- Post updated at 12:54 AM ---------- Previous update was at 12:48 AM ----------

Moreover, I am suspecting if I can have two while read statements?

the reason I have two is that I am trying to change field 7 "04:55" to not display or include the semi-colon...such a long hassle code but that's all I can think of to use sed strictly for this script the code I entered just to do that function is shown below:
Code:
sed -e 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\(.\{8\}\).*$/\7/' tabc.txt | sed 's/://' | while read filetime

# 4  
hmmm, .....

First off, i doubt that this is a good usage of sed. It is generally better to work with shell built-ins and to an amazing extent this is possible once you think about it.



Quote:
Originally Posted by wolf@=NK
pretty much I did the indentation and close the while-loops using the "\" forward slash However, I still get the same error?
Sorry, my bad. I meant first and third "while-loop", not "line".

As far as your revised code goes there are still some loops not written properly. I have marked the places below:


Code:
#!/bin/bash #INSERT DO ARGUMENT HERE???
     2 
     3 #Read tabc.txt #INSERT DO ARGUMENT HERE???
     4 tabc="cat tabc.txt"
     5 
     6 #Make week 7 assignment directory
     7 wk7dir=~/"wk7dir"
     8 
     9 #Prevents duplicates and errors
    10 if [ ! -d $wk7dir ]; then
    11      mkdir $wk7dir
    12 fi
    13 
    14 #Assign appropriate variables from tabc.txt
    15 $tabc | sed -e '<statement>' |\
    16 while read fileuser filesize filedate filename ; do
    17         $tabc | sed -e '<statement>' |\
    18         sed 's/://'|\
    19         while read filetime; do
    20 
    21              #Change filesize
    22              dd if=/dev/zero of=$wk7dir/$filename bs=$filesize count=1
    23 
    24              #Create files based on date and filename
    25              touch -d $filedate $wk7dir/$filename
    26 
    27              #Changes file permissions to allow read, write, and execute to all users
    28              find ~/"wk7dir" -type f -exec chmod 755 {} \;
    29 
    30              ls -lR --time-style="+%Y%m%d" "wk7dir" |\
    31              sed -e '<statement>' |\
    32              while read filedatestamp ; do
    33 
    34                      #Modify file time
    35                      touch -mt $filedatestamp$filetime $wk7dir/$filename
    36 
    37              done
    38      done
    39 done


I hope this helps.

bakunin
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #495
Difficulty: Easy
Blocks of code cannot be nested within each other to form sub-blocks.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Sh: -c: line 0: syntax error near unexpected token `(' how to resolve this

Below query is not working for me. Please help me on this DATA EXCLUDE STATEMENT: TABLE:\"LIKE \'%\_HISTORY\'\", TABLE:\"LIKE \'%\_HIST\'\", TABLE:\"in \(select tname from tab where REGEXP_LIKE(TNAME,\'\_H$\'\))\", TABLE:\"LIKE \'%\_LOG\'\", TABLE:\"LIKE \'DW\_%\'\", TABLE:\"LIKE... (1 Reply)
Discussion started by: princy
1 Replies

2. Shell Programming and Scripting

Del: line 13: syntax error: unexpected end of file

1 echo -e "Enter a filename" 2 read filename 3 if 4 then 5 echo -e "do you want to delete?" 6 read answer 7 if 8 then rm myfirst 9 else 10 echo -e "file not deleted" 11 fi 12 exit0 (1 Reply)
Discussion started by: Speedy
1 Replies

3. Red Hat

sh: module: line 1: syntax error: unexpected end of file

Hi, We have installed linux6(RHEL) OS and installed datastage application on that. First time installation worked fine and our all services related to datastage was up and running. When we stopped the datastage and restarted its giving below error while restart:- ./uv -admin -start DataStage... (0 Replies)
Discussion started by: prasson_ibm
0 Replies

4. Shell Programming and Scripting

line 15: syntax error: unexpected end of file

Hi all, I am very new to programming and even newer to this forum as well, so I apologize if this should have been in the Newbie category, but... I am currently trying to figure out Shell Scripting and am running into problems early. Not having taken any kind of programming class, I am not even... (2 Replies)
Discussion started by: ccorder22
2 Replies

5. Shell Programming and Scripting

syntax error at line 752: `end of file' unexpected

Hi, I'm having a syntax error at line 752: `end of file' unexpected. However, i didn't make any changes on line 752. I just inserted a new code in an existing program. Can anyone please check if there is something wrong with my code: if then lline=`tail -5 $badfile` ... (3 Replies)
Discussion started by: chryz
3 Replies

6. Shell Programming and Scripting

mkmkfiles.imake: line 51: syntax error: unexpected end of file

Hi, i am installing glut-3.5 using that ./mkmkfiles.imake its showing an error msg as root@lxdevenv:~/Desktop/openGL/glut-3.5# ./mkmkfiles.imake ./mkmkfiles.imake: line 51: syntax error: unexpected end of file root@lxdevenv:~/Desktop/openGL/glut-3.5# actually there are 49 lines in... (3 Replies)
Discussion started by: Ravikishore
3 Replies

7. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: debojyoty
3 Replies

8. Shell Programming and Scripting

Help on shell script : syntax error at line 62: `end of file' unexpected

Hi All, I have written a korn script (code pasted below). It is giving the error while debugging "new.sh: syntax error at line 62: `end of file' unexpected". I have re-written the whole code in VI and explored all help related to this error on this Unix forum and tried it. Somehow, I could... (7 Replies)
Discussion started by: schandrakar1
7 Replies

9. UNIX Desktop Questions & Answers

line 3: syntax error near unexpected token `('

Hi All I've used UNIX in the past experimenting with commands through terminal but thats about it. Im now currently teaching myself "C". Using a book from the library, the first chapter asks you run and compile your program from a command-line prompt. As you will see the program is very simple,... (4 Replies)
Discussion started by: camzio
4 Replies

10. Solaris

syntax error at line 59: `end of file' unexpected

Hello... I'm trying to run the sshd script, but I keep geting the Syntax errot message . Here's the last few lines on the script. set nu in vi shows 58 lines, but I keep getting error referring to line 59. Any help is appreciated. Thanks, Remi else echo... (4 Replies)
Discussion started by: Remi
4 Replies

Featured Tech Videos