- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to validate input as an integer
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:19 PM
09-11-2005 09:19 PM
I have a script that requires to input hour and minute, But i am unable to validate the input as integer. Is there any unix command that i can include in the shell script to validate it.
Including the shell script
-------------------------------------------
printf "\nSchehule Time"
while [ "$Hour" -lt "1" -o "$Hour" -gt "12" ]
do
printf "\nHour: (1-12) [08] "
read Hour
if [ "$Hour" = "" ]; then
Hour=08;
fi
done
echo "$?"
while [ "$Minute" -lt "1" -o "$Minute" -gt "59" ]
do
printf "Minute: (01-59) [30] "
read Minute
if [ "$Minute" = "" ]; then
Minute=30;
fi
done
printf "\nTime scheduled is $Hour:$Minute\n"
-------------------------------------------
Please advice me,
AJi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:39 PM
09-11-2005 09:39 PM
Re: How to validate input as an integer
You can use expr to treet that as an integer:
Ex:
i=1
echo $i
while [ $i -le 10 ]
do
echo " $i is less than 10 ]
i=`expr $i + 1`
done
--------------
Hope this will help ,
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:42 PM
09-11-2005 09:42 PM
Re: How to validate input as an integer
typeset -i hour
read hour
This will then guarantee that $hour is an integer. If the user enters text instead of a number, the value will be 0
You can then validate the range is between 1 and 12 as required, happy that $hour will be a proper integer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:50 PM
09-11-2005 09:50 PM
Re: How to validate input as an integer
Here you have ti change ,
read Minute
if [ "$Minute" = "" ]; then
You need to remove the quote to treet as a integer , and you can do the comparisiion statement like , -le (Less than ) -ge (Greater than ) or -eq (Equal ) , or = ,
so try making :
read Minute
if [ $Minute = integer_value ]
then
..
Also you can use the typset -i ,
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:52 PM
09-11-2005 09:52 PM
Re: How to validate input as an integer
I hope you provided the info. But please explain how to limit hours betwwen 1-12 with the case syntax
Regards
AJi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:53 PM
09-11-2005 09:53 PM
Re: How to validate input as an integer
its typeset , sory , mistake in my last post. np pls.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2005 09:56 PM
09-11-2005 09:56 PM
Re: How to validate input as an integer
I got the logic of the case syntax. Thanks a lot. It helps me to solve the problem
Thanks for the support guys.
regards,
AJi