Need help with -exec cp command.

I have a ksh script that contains the following:

find /dir1/dir2 -type f -name "FILE.*" -newer /dir1/dir2/afterme.txt -exec cp /dir1/dir2/dir3 {} \;

When I run it from the cli, it runs fine. When I run it from the ksh script I get
find: missing argument to `-exec'

I also tried -exec cp {} ... and I still got the same error. What's the missing argument?

Assuming you want to copy the files to the directory /dir1/dir2/dir3:

find /dir1/dir2 -type f -name "FILE.*" -newer /dir1/dir2/afterme.txt -exec cp {} /dir1/dir2/dir3 \;

Regards

At the bottom of my first post, I mentioned that I already tried it that way. Still got the same error.

Anyone else?

Anyone?

Might the below script will help you ;

find /dir1/dir2 \(-type f -name "FILE.*" -a -newer /dir1/dir2/afterme.txt \) -exec cp {} /dir1/dir2/dir3/ \;

Regards,

Thanks but nah. It returned this error:

find: invalid predicate `(-type'

You need a space after the opening parenthesis. It's not clear why you were getting the error message in the first place but maybe just retyping a different command coincidentally fixes whatever was wrong (missing characters? Random invisible characters?)

I took your advice and retyped. Still getting the same error. If I type the command it works. If I run it from the ksh script I get the error:

find: missing argument to `-exec'

Hello,

I really still need some help in getting this script to work.

If I type out the command it works. If I put the exact same command in a .ksh script, I get the error:

Find: missing argument to `-exec`.

Why would it do this in the script and not at the command line?

First question:
Does the first line of the script look like this?

#!/bin/ksh

Next question:
does the output of this show any weird characters on the problem line

od -c myscript.sh

Finally - cut and paste (do not retype) the whole line that is a problem so we can read it. Include full command line above it and below it. Please give us the OS and shell -- ksh88 or ksh93.

Or a workaround

find /dir1/dir2 -type f -name "FILE.*" -newer /dir1/dir2/afterme.txt | \
while read filename 
do
    cp $filename /dir1/dir2/dir3/
done

I'm with Jim on this. The .ksh extension does not at all effect which shell will be invoked. If it's a sh with a different PATH than you run interactively, you could be getting another version of find than you get at the command line. Another thing to watch out for is DOS carriage returns in the script. You're not writing it on a Windoze machine and uploading it to your Unix account, are you?

No, I used vi to create the file. I had the #!/bin/ksh at the top of the line but I was getting this error:

: bad interpreter: No such file or directory

Here is the error I get when I run the above from the script:

: command not founde 1:
./scriptname.ksh: line 7: syntax error: unexpected end of file

I just don't get it. From the command line it works. From ./scriptname.ksh ERROR!

Well why not tell what OS you are running?
Then type which ksh So we know what to put on the first line...
Then if it works fine on command line, I believe you have typos in your script...
I would recall the command line AND type v (call vi...) then save the command line with a name such as gogo.ksh, then chmod then ./gogo.ksh.
If this works, then you have just proven the problem lies in your script

if #!/bin/ksh does not work, then you prolly do not have the original korn shell.
what is the output of:

 echo $0  $SHELL 

from your command line?

It really is hard to help if you cannot give us what we ask...

Try typing:

which ksh

Then, enter the correct bath to ksh in your script header.

On my host, ksh is in /usr/bin/ksh. My script header would be:

#!/usr/bin/ksh

edit: added code tags

note: This simply encapsulates the responses of vbe and jim mcnamara

This is the output:

-bash /bin/bash

Also, the OS is Redhat 9 (Shrike).

So have you tried now with 1rst line:
#!/bin/bash

Yeah I tried that and I still got: : bad interpreter: No such file or directory

I also tried #!/usr/bin/bash

Still got the same thing. Thanks for the help so far, keep the suggestions coming.