Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script with Arguments and echo Response

Status
Not open for further replies.

MagnumVP

IS-IT--Management
Jul 9, 2002
109
US
I'm attempting to write a script that will search a particular directory and a set of files though a set of line arguments.

Example:

$script /usr/bin/ksh file1 file2 ..... file[n]

I want it to echo the path name and the file name. If the directory doesn't exist then I want it to echo "incorrect directory". If the file(s) are wrong then I want it to echo which argument is incorrect.

Here is what I have so far:

#! /bin/ksh
if test -d $1
then
directory=$1
shift
for file in $*
do
find $directory -name $file -print
done
else
echo "The directory of $1 could not be located."
echo "Please try a different directory"
echo
fi

This script works fine if the directory is incorrect. But what if the files are incorrect. Right now it doesn't say a thing.

Any Thoughts?

MagnumVP
 
Not tested it but try something like this: -

do
if test -f ${directory}/${file}
then
find etc....
else
echo $file" not found"
fi
done


Ged Jones

Top man
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top