The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 06:50 PM
array type has incomplete element type jaganadh High Level Programming 1 07-24-2007 03:54 AM
String type to date type rinku Shell Programming and Scripting 1 05-30-2007 06:56 AM
Human readable type vs MIME type detection using file spauldingsmails Shell Programming and Scripting 0 03-22-2007 12:43 AM
find . -type d -exec cd {} \; shimont UNIX for Dummies Questions & Answers 2 11-23-2005 11:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2005
madmat madmat is offline
Registered User
  
 

Join Date: Aug 2005
Location: Paris
Posts: 80
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
  #2 (permalink)  
Old 09-21-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 06:30 AM.. Reason: Enhanced to check for +ve and -ve numbers.
  #3 (permalink)  
Old 09-21-2005
madmat madmat is offline
Registered User
  
 

Join Date: Aug 2005
Location: Paris
Posts: 80
Hi vino
Funny code
Thx for it, I'll find some ideas for my problem.
Rgds
  #4 (permalink)  
Old 04-10-2009
fnds fnds is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 3
<deleted>

Last edited by fnds; 04-10-2009 at 02:54 PM.. Reason: posted on wrong thread
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 10:45 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