ksh : find value type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh : find value type
# 1  
Old 09-19-2005
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 Smilie
# 2  
Old 09-21-2005
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 07:30 AM.. Reason: Enhanced to check for +ve and -ve numbers.
# 3  
Old 09-21-2005
Hi vino
Funny code Smilie
Thx for it, I'll find some ideas for my problem.
Rgds
# 4  
Old 04-10-2009
<deleted>

Last edited by fnds; 04-10-2009 at 03:54 PM.. Reason: posted on wrong thread
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find file type recursively and move

Hello, I supposed that it was working fine but now I see that it's not working as expected. I am running under ubuntu14.04, trusty. My plan was to search folderA and all subdirectories and move any txt file to destination folder, folderB : find /home/user/folderA/ -type f -iname "*.txt"... (0 Replies)
Discussion started by: baris35
0 Replies

2. Shell Programming and Scripting

What is wrong with 'find . -maxdepth 1 -ctime -7 -type f'?

Have you tried running the command below? On the same RHEl 6.8 or 6.6. It will give you different output. find . -maxdepth 1 -ctime -7 -type f rpm -qa|grep find findutils-4.4.2-9.el6.x86_64 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.8 (Santiago) # (6 Replies)
Discussion started by: invinzin21
6 Replies

3. Homework & Coursework Questions

Shell script to find file type

1. The problem statement, all variables and given/known data: Write a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase: Windows ASCII if the files is an... (4 Replies)
Discussion started by: kwatt019
4 Replies

4. Shell Programming and Scripting

KSH - type ENTER to continue

Hello, Is ther any way to run a loop which promt an echo"waiting for user to hit ENTER" sleeps for an iterval and once user hit the ENTER key the loop exit and the script continue to the next stage? I need this ASAP !!! Thanks!! (9 Replies)
Discussion started by: LiorAmitai
9 Replies

5. Shell Programming and Scripting

Find command return type

Hi all does find command return anything if the file to be searched is not found? Like if I search from a file in a dir does it return false or null if the file is not found? Please suggests. (3 Replies)
Discussion started by: Veenak15
3 Replies

6. UNIX for Advanced & Expert Users

changing shell type from sh to ksh

Could someone please advise, what's the best way to changing the shell type from sh to ksh. When I login into a unix server it takes you directly to sh, is there a way of amending the .profile to use ksh instead. Or is there some other way ? Ideally it would be good to be done from the login... (10 Replies)
Discussion started by: venhart
10 Replies

7. UNIX for Advanced & Expert Users

User friendly Unix ksh prompt to type directories/files

Hello, I wanted to setup user friendly ksh command prompt, by typing first character of files or directories and then tab bring up whole word. No need to type whole file/directory/command names. Example: cat a file like university just typing un and then tab bring up whole university wod.... (3 Replies)
Discussion started by: abdurrouf
3 Replies

8. Shell Programming and Scripting

Does KSH support data type conversion?

Hello,everyone here. I'm coding with KSH to achieve exploring the disk space and judging whether it closes to overflow.But It seems that no one way to convert a string variable to integer. df | read A B C D E F G H I J K L print ${L} Can I convert L to integer type? Thanks for... (2 Replies)
Discussion started by: joshuaduan
2 Replies

9. UNIX for Dummies Questions & Answers

find . -type d -exec cd {} \;

Hi all Can anyone tell me why this is not working ? i saw somewhere that i must have serach (execute) permission which i have but it still wont work thx (2 Replies)
Discussion started by: shimont
2 Replies
Login or Register to Ask a Question