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 and shell scripting languages 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 06:10 AM
need to move find results pimentelgg Shell Programming and Scripting 9 12-20-2007 06:00 PM
find results Carmen123 UNIX for Dummies Questions & Answers 5 08-10-2005 11:27 AM
script returns prompt kburrows UNIX for Dummies Questions & Answers 3 10-06-2003 11:12 AM
cant find command that returns blank line jeffersno1 UNIX for Dummies Questions & Answers 2 11-15-2001 04:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-25-2008
blt123 blt123 is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 19
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
  #2 (permalink)  
Old 04-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #3 (permalink)  
Old 04-25-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,333
This should work too:


Code:
find . -mtime -1 ! -name "*file*"

Regards
  #4 (permalink)  
Old 04-25-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
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 (permalink)  
Old 04-25-2008
blt123 blt123 is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 19
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 04:23 PM..
  #6 (permalink)  
Old 04-25-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,333
Use double quotes:


Code:
find . -mtime -1 ! -name "*file*"

Regards
  #7 (permalink)  
Old 04-26-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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)?
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0