The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Type I and Type II Errors - The Heart of Event Processing iBot Complex Event Processing RSS News 0 12-05-2007 03:50 PM
array type has incomplete element type jaganadh High Level Programming 1 07-24-2007 12:54 AM
String type to date type rinku Shell Programming and Scripting 1 05-30-2007 03:56 AM
Human readable type vs MIME type detection using file spauldingsmails Shell Programming and Scripting 0 03-21-2007 09:43 PM
find . -type d -exec cd {} \; shimont UNIX for Dummies Questions & Answers 2 11-23-2005 08:42 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-19-2005
Registered User
 

Join Date: Aug 2005
Location: Paris
Posts: 75
ksh : find value type

Hi,

Simple question :
How to find the value type from a variable :
Ex : var="1" => type is numeric
var="a" => type is character

Thx
Reply With Quote
Forum Sponsor
  #2  
Old 09-21-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Have a look at this

Code:
$ cat mad.ksh            
#! /bin/ksh

[[ -z "$1" ]] && echo "I cant work without an input" && exit 1

INPUT="$@"

[[ "$INPUT" == ?(+|-)+([0-9]) ]] && echo "$INPUT is numeric" && exit 0

[[ "$INPUT" == +([a-zA-Z]) ]] && echo "$INPUT is character" && exit 0

[[ "$INPUT" == *([0-9]|[a-zA-Z])* ]] && echo "$INPUT is alpha-numeric" && exit 0
Code:
$ ./mad.ksh 123
123 is numeric
$ ./mad.ksh abc 
abc is character
$ ./mad.ksh abc123
abc123 is alpha-numeric
Not very perfect. Atleast will get you started.

-vino

Last edited by vino; 09-21-2005 at 03:30 AM. Reason: Enhanced to check for +ve and -ve numbers.
Reply With Quote
  #3  
Old 09-21-2005
Registered User
 

Join Date: Aug 2005
Location: Paris
Posts: 75
Hi vino
Funny code
Thx for it, I'll find some ideas for my problem.
Rgds
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0