When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file.
Once I get this command to work, I will add the "delete" part to the command. Just trying to make sure I have all the right files listed first.
The syntax is kind of oddball, and chances are your interactive script is executed by something like ksh or bash, whereas your script is presumably executed by /bin/sh.
In particular, I imagine the unquoted exclamation mark might have some unseen side effects.
Try fix the find command to adhere to the spec:
find . -mtime -1 -a \! -name file\*
Also investigate whether the PATH is somehow different inside the script, and/or you have functions or aliases which interfere in the interactive shell.
Is your shebang line different from your login shell. Maybe the ! is having unwanted side effects and since your are interested only in files add the -type switch too.
Franklin52: That's not it, single quotes are stronger than double, so the result should be the same (you want to prevent the asterisk from being expanded by the shell).
blt123: can you run the interactive shell with -x too?
See the + lines there? You can get them from an interactive session just like from a script. (No need to start a subshell either, you can just say set -x to enable them; set +x to turn them back off.)
The crucial question is whether the find command gets expanded to something unexpected.
Also, can you try with a hard-coded path to your find binary (/usr/bin/find I would guess)?