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!

creating script error messages

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, just a quick newbie question,

I'm writing a script which takes a filename as a parameter and I'm writing the error messages such as -

if [ -d $file ] then echo "$file is a directory"

but how do I create one that is returned when there is a particular character or string in the name of the file ?

many thanks

 
Probably more than one way to do this,
but here's one way.

#!/usr/bin/ksh
TEXT=abc #put what you want to search for here

MATCH=`echo $FILE_NAME|grep $TEXT`
if [ ${#MATCH} -gt 0 ]
then
echo "Found a Match!
else
echo "No match found!"
fi

# you can also change the grep
# to a grep -i if you want to ignore case Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top