question on 'find' in a script

question on 'find' in a script

Post by Ray Jon » Wed, 04 May 1994 01:15:54




Quote:>if i put 'find' command in a piece of script, how could i make it take
>command arguments? ie. i want to delete files with .tmp extension, following
>will just do it:
>find . -name \*.tmp -ok rm {} \;
>then i want to put above in a file, say 'fdel', and i'd like it works in a
>way like:
>'fdel *.tmp', or 'fdel *.dat', etc.
>how? i've tried something without success. any pointers are appreciated.

You are getting trashed because of shell expansions of the *.tmp prior to
getting into the script.  Try something like:

find . -name \*.$1 -ok rm {}\;

The $1 will be replaced by the first argument of the "fdel" command as in
fdel dat
will be run as
find . -name \*.dat -ok rm {} \;

Good luck

 
 
 

question on 'find' in a script

Post by Patrick Seema » Wed, 04 May 1994 17:33:42



Quote:>find . -name \*.tmp -ok rm {} \;

>then i want to put above in a file, say 'fdel', and i'd like it works in a
>way like:

>'fdel *.tmp', or 'fdel *.dat', etc.

You may be looking for something like

#!/bin/sh
find . -name $1 -ok rm {} \;

Put this in a file called 'fdel' and remove temp files with fdel '*.tmp'.

greetings, pat