The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-20-2008
angelap angelap is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
Comparing Special characters (i.e. -,\,/) in an if statment

I need to validate the special characters of a date (the characters between the year and month & month and day). The data filed is being populated by users and read into the script vi an argument. I want to ensure that the date is a '-' (dash) and not a '/' or '\' (slash).

The every thing I have tried has failed and I have run out of ideas. I'm new to scripting and don't know where else to turn. Please help if you can. Thanks.

# ! /bin/ksh
set -x
V_DATE='2008-08-30'
echo $V_DATE
V_DATE_DASH1=`echo $V_DATE | cut -c 5`
echo 'INFO V_DATE_DASH1: ' $V_DATE_DASH1>>${LOGFILE}
V_DASH='-'
echo 'INFO V_DASH:'$V_DASH>>${LOGFILE}
echo $V_DATE_DASH1 = $V_DASH
if `${V_DATE_DASH1} = ${V_DASH}`
then echo 'INFO V_DATE_DASH1 is OK'>>${LOGFILE}
else echo 'ERROR V_DATE_DASH1 not a "-" '>>${LOGFILE}
usage
fi