LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to identify numeric Input (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-identify-numeric-input-765220/)

pinga123 10-29-2009 01:40 AM

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

AngTheo789 10-29-2009 04:10 AM

See http://www.linuxquestions.org/questi...n-bash-279227/
(you didn't look very hard for the solution, didn't you?)

pinga123 10-29-2009 05:14 AM

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

pinga123 10-29-2009 05:18 AM

Quote:

Originally Posted by AngTheo789 (Post 3736361)
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?

chrism01 10-29-2009 08:50 PM

Use the top bar
Quote:

Home Forums HCL Reviews Tutorials Articles Search
click on Search, then in first option, click 'Advanced Search'


All times are GMT -5. The time now is 05:41 PM.