ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.