The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 11:23 AM
grep to find content in between curly braces, "{" and "}," keshav_rk Shell Programming and Scripting 4 08-09-2007 10:14 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 04:15 AM
korn shell "loops & arrays" muzica Shell Programming and Scripting 7 09-23-2004 03:02 PM
Korn shell "select" command mpegler Shell Programming and Scripting 2 06-23-2002 09:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-18-2002
jwperry jwperry is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 7
Find -name "*.txt" in Korn Shell Script

The following find command works on the Korn Shell command line:

find . \( ! -name . -prune \) -type f -name "*.txt" -mtime +100

In the particular directory I'm in, the above find will list correctly the three text files that exist that haven't been modified in over 100 days:

./ep75150aA.txt
./ep13217a_rx_history11122001150339.txt
./ep13217a_rx_history12112001162013.txt
./Report2_ep75150a.txt


When that same find command runs within a Korn Shell script (against the same dir), it does not list the three files. It only shows:

drwxrwxrwx 2 7 devel 150528 Jul 18 11:28 .


What am I missing?

Thanks
  #2 (permalink)  
Old 07-18-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try changing
"*.txt"
to
'*.txt'
  #3 (permalink)  
Old 07-18-2002
jwperry jwperry is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 7
I was thinking I could get away with minimal detail on my first post, but, I was wrong - sorry about that. The script actually accepts parameters that will be used in the find command. I echo the find command to screen, and it 'looks ok" - see snippets below:

#!/bin/ksh
PURGEPATH=$1
DAYSOLD=\'$2\'
FILESPEC=\'$3\'
LOGINDICATOR=$4

###DAYSOLD=$2
###FILESPEC=\\$3 tried this
###FILESPEC=\"$3\" and this


...(The script switches to PURGEPATH)....

The find looks like this:

find . \( ! -name . -prune \) -type f -name $FILESPEC -mtime $DAYSOLD | xargs ls -ldrt >> $LOGFILE


I echo the 'variable populated' find command to the screen (and logfile), and it looks like:

find . \( ! -name . -prune \) -type f -name '*.txt' -mtime '+100' | xargs ls -ldrt


Finally, I put the 'hard-coded' find in the script, with -name '*.txt' (i.e. exactly the second find, above), and it worked! So, even though I echo the 'variable-populated' version to screen, and, it looks just like the 'hard-coded' version, the variable version ($FILESPEC, $DAYSOLD) does not work!


I hope I made that clear. My login shell is ksh. The script is ksh.
What is it about the use of the variables am I missing?


Thanks again!
  #4 (permalink)  
Old 07-19-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
One solution is like this...
Code:
#! /usr/bin/ksh
TARGET=$1
eval find . -name \'$TARGET\' -print | xargs wc -l
exit 0
And the other other is to:
set -o noglob
at the top of the script. This affects everything though.
Closed Thread

Bookmarks

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 03:55 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