#! /bin/sh # Script name: finder # Bourne shell script # A menu program ############################## ## DISCLAIMER DISCLAIMER ############################################# ############################## # # This shell script is supplied with no guarantee. # It is given on the understanding that the supplier will not be held # responsible for any inaccuracies, disruption or loss of data # incurred through use of this script. # Use of this script implies acceptance of the above disclaimer. # ############################## ## DISCLAIMER DISCLAIMER ############################################# ############################## # a=NO while [ $a = "NO" ] do clear echo "Please enter the name of the starting directory \c" read sdir if [ -d "$sdir" ] then a=YES else echo "Sorry.. That is not a valid directory name.. Try again" sleep 1 fi done b=NO while [ $b = "NO" ] do clear echo "Starting from $sdir" echo "Please enter the file name to find (wildcards are allowed) \c" read fname # Assign a value to the variable of no value is entered fname=${fname:-null_value} # Test whether the alternative value has been assigned if [ "$fname" = "null_value" ] then echo "You must enter a filename to find!" sleep 1 else echo "OK... Starting the find operation Do you want the 'found' files to be written to a file as well as being displyed on the screen \n Type Y or y for Yes, RETURN or Any character = No \c" read ans if [ "$ans" = "Y" -o "$ans" = "y" ] then sfile=/tmp/found.$$ echo "Details will be stored in $sfile" else sfile="" fi echo "\nError messages are being suppressed. Please wait.. This may take some time\n" sleep 3 if [ -z "$sfile" ] then find $sdir -name "$fname" -print 2>/dev/null | more val=$? else find $sdir -name "$fname" -print 2>/dev/null | tee $sfile | more val=$? fi if [ $val -ne 0 ] then echo "It appears that an error occurred and 'find' did not work" echo "...or... Nothing was found!" else echo "\nFind operation completed" fi b=YES fi done