LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-29-2009, 01:40 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
How to identify numeric Input


Hi guys when i execute my script it says integer expression expected .How would i handle this in my script please suggest.


Please Enter Your Age sa
./ifexercise.sh: line 7: [: sa: integer expression expected
./ifexercise.sh: line 10: [: sa: integer expression expected
Please enter proper Input

Content of my script.
#!/bin/bash
echo "Please Enter Your Age"
read age
retirement_age=65
if [ -z "$age" ]
then
echo "dont enter empty string"
elif [ "$age" -gt $retirement_age ]
then
echo "You Should retire now"
elif [ "$age" -le $retirement_age ]
then
echo "You are young"
else
echo "Please enter proper Input"
fi
 
Old 10-29-2009, 04:10 AM   #2
AngTheo789
Member
 
Registered: Sep 2009
Posts: 110

Rep: Reputation: 24
See http://www.linuxquestions.org/questi...n-bash-279227/
(you didn't look very hard for the solution, didn't you?)
 
Old 10-29-2009, 05:14 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
I have Modified my script As follows:




#!/bin/bash
echo "Please Enter Your Age"
read age
retirement_age=65
if [ -z "$age" ]
then
echo "dont enter empty string"
elif [ ! `expr $age + 1 2>/dev/null` ]
then
echo "Please Enter Numeric Number"
elif [ "$age" -gt $retirement_age ]
then
echo "You Should retire now"
elif [ "$age" -le $retirement_age ]
then
echo "You are young"
else
echo "Please enter proper Input"
fi
 
Old 10-29-2009, 05:18 AM   #4
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by AngTheo789 View Post
See http://www.linuxquestions.org/questi...n-bash-279227/
(you didn't look very hard for the solution, didn't you?)
How do i find the questions that are already posted as there are so many questions in here?
 
Old 10-29-2009, 08:50 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,286

Rep: Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347Reputation: 2347
Use the top bar
Quote:
Home Forums HCL Reviews Tutorials Articles Search
click on Search, then in first option, click 'Advanced Search'
 
  


Reply


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
How to read "identify" button press event, or state of "identify" blue led with IPMI? iav Linux - Server 0 01-27-2009 01:13 PM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM
Help installing Numeric-23.6 Multra Linux - Newbie 3 10-26-2004 05:14 PM
chmod u+s = numeric? kidwired Linux - Newbie 4 01-19-2003 11:24 PM
Numeric Permissions MelLinux Linux - General 3 10-18-2002 01:51 PM


All times are GMT -5. The time now is 02:58 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration