1748136 Members
3630 Online
108758 Solutions
New Discussion

syntax error at line

 
SOLVED
Go to solution
NDO
Super Advisor

syntax error at line

Hi!

 

I am trying to create a script tha copies files from one directory to the other on the same system, like this:

for JOB in `ls -lrt | awk '{if ($6 == "Aug" && $8 != 2010)print $9}'`
cp -p /data/xxxx/yyyy/zzzz/processed/$JOB /data/xxxx/yyyy/zzzz/processed/Ago11/
done

 

But I am having the following error:

 

 Syntax error at line 2 : `cp' is not expected

 

Please can you help

 

FR

3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: syntax error at line

Hi:

 

The problem is that 'do ... done' needs to define the loop.  You are missing the 'do'.

 

for JOB in `ls -lrt | awk '{if ($6 == "Aug" && $8 != 2010)print $9}'`
do
cp -p /data/xxxx/yyyy/zzzz/processed/$JOB /data/xxxx/yyyy/zzzz/processed/Ago11/
done

Regards!

 

...JRF...

NDO
Super Advisor

Re: syntax error at line

Hi

 

Sorry, my stupid mistake...

 

its now working

 

thanks a lot

Dennis Handly
Acclaimed Contributor

Re: syntax error at line

Or if you like, you can put the do on the for line:

for JOB in $(ls -lrt | awk '{if ($6 == "Aug" && $8 != 2010) print $9}'); do
   cp -p /data/xxxx/yyyy/zzzz/processed/$JOB /data/xxxx/yyyy/zzzz/processed/Ago11/
done