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
Try changing
".txt"
to
'.txt'
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!
One solution is like this...
#! /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.