Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-01-2012, 07:36 AM   #1
Registered: Feb 2012
Posts: 58

Rep: Reputation: Disabled
checking for an integer

i want to check whether entered argument is an integer using if

anyone can u help me??
Old 03-01-2012, 07:43 AM   #2
Satyaveer Arya
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
What code you are using? what argument have you entered? what have you tried so far? Please be more specific, give more details....
Old 03-01-2012, 08:13 AM   #3
Registered: Feb 2012
Posts: 58

Original Poster
Rep: Reputation: Disabled
i have passed a number like 340

nd my code was
echo $1 | grep '^[0-9]$'
echo $?
but always i m getting as 1
whatevr may be the argument
Old 03-01-2012, 10:21 AM   #4
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
if [[ $1 =~ ^[0-9]+$ ]; then


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Using 64bit integer raven Programming 6 03-13-2008 12:05 PM
64 bit integer rajesh_b Programming 4 07-18-2006 06:43 AM
Integer Numbers in C Mercurius Programming 24 10-20-2005 09:54 AM
Integer To a String in C Bean101 Programming 2 05-27-2004 04:46 AM
64 bit integer fahad153 Programming 9 08-26-2003 02:03 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:10 PM.

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