LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 11-26-2008, 09:30 AM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
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.
 
Old 11-26-2008, 09:40 AM   #2
nehaandrew
Member
 
Registered: Nov 2008
Posts: 53

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


Linux

Last edited by nehaandrew; 11-30-2008 at 01:16 AM.
 
Old 11-26-2008, 09:41 AM   #3
nehaandrew
Member
 
Registered: Nov 2008
Posts: 53

Rep: Reputation: 15
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.

Last edited by nehaandrew; 11-26-2008 at 09:46 AM.
 
Old 11-26-2008, 09:43 AM   #4
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
oh sorry. I am using korn shell.

A check something similar to

Quote:
[[ -z "$var" ]

Last edited by tostay2003; 11-26-2008 at 10:04 AM.
 
Old 11-26-2008, 06:14 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed search for variable and delete entire line, but variable contains forward /'s Passions Programming 2 11-10-2008 03:44 PM
script doesn't want to see my variable as an integer. Xerop Linux - Software 5 09-08-2008 04:58 AM
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 05:21 PM
Test variable is an integer in shell judgex Programming 1 06-03-2006 09:12 PM
write() a variable(integer) to socket? koyi Programming 6 07-08-2004 09:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration