Training scripts
Fred Yankowski
fred at ontosys.com
Tue Jan 27 23:55:56 CET 2004
On Tue, Jan 27, 2004 at 05:33:06PM -0500, Matej Cepl wrote:
> find $MAILDIR/_junk/ -type f -name 10\* \
> -exec sh -c "export STR=`basename '{}'`" \; \
> -exec echo $STR \;
>
> The script prints only 143 empty lines. What am I doing
> incorrectly?
That exported STR value survives only as long as the 'sh' program run
in the first '-exec' parameter. It's gone when the second '-exec'
process runs.
I think the following would do what you intended the above to do:
find $MAILDIR/_junk/ -type f -name 10\* -print | sed 's#.*/##'
where that sed script is effectively running 'basename' over a stream.
My feeling is that you are trying to do too much inside 'find' itself.
I prefer to feed the output of 'find' into 'xargs' or into a shell
'while' loop:
find $MAILDIR -type f -print |
while read MAILFILE; do
STR=$(basename $MAILFILE)
echo $STR
... whatever else ...
done
More information about the Bogofilter
mailing list