The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh Checking if variable has 5 digits developncode UNIX for Dummies Questions & Answers 3 04-08-2008 12:57 PM
Digits display Spoorthi16 UNIX for Dummies Questions & Answers 3 10-01-2007 05:26 PM
making sure input are digits bebop1111116 High Level Programming 1 10-21-2006 02:32 PM
How to cut last 10 digits off psarava Shell Programming and Scripting 4 08-29-2006 12:52 AM
diff. b/t chars and digits mezzanine Shell Programming and Scripting 1 11-17-2005 09:37 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-21-2007
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 288
Lightbulb Only Digits as input

Hi All,
I am new to shell script.
I wrote a very small script that takes only digits as input-
but there is some problem in that.can you help me in debugging that.

#!/bin/ksh
echo "Digits as input"
read number
digit='eval [0-9][0-9][0-9]'
if [[ number -eq $digit ]]
then
echo "Entered number is a digit"
else
echo "0"
fi

Please modify this one or without AWK give me some inputs.

Thanks,
Namish
Reply With Quote
Forum Sponsor
  #2  
Old 08-21-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
#!/bin/ksh
echo "Digits as input"
read number

test=`echo "$number" | egrep "^[0-9]+$"`

if [ "$test" ]
then
   echo "Entered number is a digit"
else
   echo "0"
fi
Reply With Quote
  #3  
Old 08-21-2007
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 288
Thumbs up

Thanks robotronic.

I appericiate your help and quick reply.

Thanks
Namish
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0