LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   variable integer (https://www.linuxquestions.org/questions/programming-9/variable-integer-686357/)

tostay2003 11-26-2008 09:30 AM

variable integer
 
Is there any command which checks whether a variable is an integer.

I don't want to write a function for this. Is there an inbuilt command that can verify if a variable is integer.

nehaandrew 11-26-2008 09:40 AM

It'd help if you let us know what programming language you are using for ur application!
:)

Linux

nehaandrew 11-26-2008 09:41 AM

For Java

You can try


boolean isVarAnInt = false
try {

Integer temp = new Integer(variableName);
if (temp.intValue() > 0 || temp.intValue() < 0 || temp.intValue() == 0) {
System.out.println("Input Variable Is An Integer");
isVarAnInt = true;
}

} catch (NumberFormatException err) {
System.out.println("Input Variable Is Not An Integer");
}



I haven't compiled the above code. So, there might be some small syntax issues that you might need to fix using ur IDE.

tostay2003 11-26-2008 09:43 AM

oh sorry. I am using korn shell.

A check something similar to

Quote:

[[ -z "$var" ]

chrism01 11-26-2008 06:14 PM

See this thread http://www.linuxquestions.org/questi...n-bash-279227/
In short, no, not like that.


All times are GMT -5. The time now is 09:14 PM.