![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Secure Search Returns Best Results | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 02:10 AM |
| need to move find results | pimentelgg | Shell Programming and Scripting | 9 | 12-20-2007 03:00 PM |
| find results | Carmen123 | UNIX for Dummies Questions & Answers | 5 | 08-10-2005 07:27 AM |
| script returns prompt | kburrows | UNIX for Dummies Questions & Answers | 3 | 10-06-2003 07:12 AM |
| cant find command that returns blank line | jeffersno1 | UNIX for Dummies Questions & Answers | 2 | 11-15-2001 01:14 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
FIND returns different results in script
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. COMMAND LINE svdw1234 : find . -mtime -1 ! -name file\* . ./test_purge svdw1234 : SCRIPT + find . -mtime -1 ! -name file\* . ./test_purge ./test_purge/file_test_purge_subdir.txt ./file_sqr_test.txt ./file.txt + return_code=0 Thanks, Barbara |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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: Code:
find . -mtime -1 -a \! -name file\* |
|
#3
|
|||
|
|||
|
This should work too:
Code:
find . -mtime -1 ! -name "*file*" |
|
#4
|
|||
|
|||
|
login shell vs. shebang line
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.
Code:
find . -mtime -1 -type f ! -name "file*" |
|
#5
|
|||
|
|||
|
I have changed to the shell to match the script and still not good results?
svdw0088 : ksh $ find . ! -name 'file*' -mtime -1 . ./test_purge $ SCRIPT first line: #!/bin/ksh SCRIPT output: + find . ! -name 'file*' -mtime -1 . ./test_purge ./test_purge/file_test_purge_subdir.txt ./file_sqr_test.txt ./file.txt + return_code=0 It still shows the files which start with the word file. I do want to exclude directory structures also. Thanks, Barbara Last edited by blt123; 04-25-2008 at 12:23 PM. |
|
#6
|
|||
|
|||
|
Use double quotes:
Code:
find . -mtime -1 ! -name "*file*" |
|
#7
|
|||
|
|||
|
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? Code:
prompt$ ksh -x $ find . ! -name 'file*' -mtime -1 + find . ! -name file* -mtime -1 . ./test_purge ./test_purge/file_test_purge_subdir.txt ./file_sqr_test.txt ./file.txt $ exit + exit 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)? |
|||
| Google The UNIX and Linux Forums |