The UNIX and Linux Forums  

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



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get rid of special characters vakharia Mahesh UNIX and Linux Applications 4 07-29-2008 02:36 PM
Special Characters in directory name tez UNIX for Dummies Questions & Answers 6 08-14-2006 08:06 PM
how to see special characters in a file using vi jingi1234 UNIX for Dummies Questions & Answers 6 10-19-2005 12:57 PM
special characters nawnaw UNIX for Dummies Questions & Answers 2 05-18-2004 04:17 PM
awk/sed with special characters apalex Shell Programming and Scripting 5 05-06-2002 05:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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
  #2 (permalink)  
Old 11-21-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,585
corrected your code but maybe I had too much "beaujolais nouveau" just now...


Code:
#!/usr/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
V_DASH="-"
echo 'INFO V_DASH:'$V_DASH
read pp
echo $V_DATE_DASH1 = $V_DASH
read pp
if [ "$V_DATE_DASH1" = "$V_DASH" ]
   then echo "INFO V_DATE_DASH1 is OK"
else echo "ERROR V_DATE_DASH1 not a "-" "
   usage  # Im waiting to see...
fi

You can tell me off, I really had too much...

Last edited by vbe; 11-21-2008 at 09:25 AM..
  #3 (permalink)  
Old 11-21-2008
angelap angelap is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
Talking

Thank you. I really appreciate the help. Have another glass to celebrate, it works.
  #4 (permalink)  
Old 11-21-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,585
It was my pleasure.


Best regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0