The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-25-2008
Registered User
 

Join Date: Feb 2002
Posts: 18
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
Reply With Quote
Forum Sponsor
  #2  
Old 04-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
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\*
Also investigate whether the PATH is somehow different inside the script, and/or you have functions or aliases which interfere in the interactive shell.
Reply With Quote
  #3  
Old 04-25-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,314
This should work too:

Code:
find . -mtime -1 ! -name "*file*"
Regards
Reply With Quote
  #4  
Old 04-25-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
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*"
Reply With Quote
  #5  
Old 04-25-2008
Registered User
 

Join Date: Feb 2002
Posts: 18
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.
Reply With Quote
  #6  
Old 04-25-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,314
Use double quotes:

Code:
find . -mtime -1 ! -name "*file*"
Regards
Reply With Quote
  #7  
Old 04-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
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
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)?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0