Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-08-2006, 06:44 AM
|
#1
|
|
Member
Registered: Oct 2005
Posts: 56
Rep:
|
understand variable type in shell script
hi guru,
in shell script i have got a variable and i want to search the type of this variable. i don't know the value is numeric or string and i am looking for a utility,function or command that return the type of the variable.
For example A=123 or A=abc. and i want to search that does A store a numeric value or sting value?
thanks in advance.
|
|
|
|
09-08-2006, 06:51 AM
|
#2
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,326
|
With ksh or bash, "typeset -p" will show the variable type, if any.
|
|
|
|
09-08-2006, 07:40 AM
|
#3
|
|
Member
Registered: Oct 2005
Posts: 56
Original Poster
Rep:
|
Quote:
|
Originally Posted by jlliagre
With ksh or bash, "typeset -p" will show the variable type, if any.
|
thanks jlliagre
but "typeset -p" shows the variables and their values in my solaris.
but my main problem is the type of the variable. is it numeric or string. i just want to learn the variable is numeric or string. i don't interest its value.
|
|
|
|
09-08-2006, 07:59 AM
|
#4
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,326
|
Nope, Solaris (I assume you really mean ksh on Solaris) shows the type of the variable, should it have a type. eg:
Code:
$ typeset -p | grep RANDOM
typeset -i RANDOM
Here RANDOM is of type integer, but the shell, being loosely typed, doesn't mandates a variable to have a type, in which case it is a string by default.
|
|
|
|
09-08-2006, 09:52 AM
|
#5
|
|
Member
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 543
Rep:
|
You could try:
A_Num=expr {$A+"0"}
if [ A_Num -eq A ] and so on ..
End
|
|
|
|
09-09-2006, 02:12 AM
|
#6
|
|
Member
Registered: Oct 2005
Posts: 56
Original Poster
Rep:
|
Quote:
|
Originally Posted by AnanthaP
You could try:
A_Num=expr {$A+"0"}
if [ A_Num -eq A ] and so on ..
End
|
Thanks,
it's a nice idea.  and it sounds good..
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:48 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|