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. |
With ksh or bash, "typeset -p" will show the variable type, if any.
|
Quote:
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. |
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 |
You could try:
A_Num=expr {$A+"0"} if [ A_Num -eq A ] and so on .. End |
Quote:
it's a nice idea. :) and it sounds good.. |
All times are GMT -5. The time now is 09:34 AM. |