- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- number or letter
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
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
05-22-2002 12:25 PM
05-22-2002 12:25 PM
i have one more question: in some cases, I have user enter a number, how can I check if indeed a number was entered, and not anything else? (opposite example would also be good!)
Thanks a lot!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2002 12:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2002 12:36 PM
05-22-2002 12:36 PM
Re: number or letter
Number
======
if [[ $VAR = +([0-9]) ]]
then
....
else
...
fi
Alphas
======
if [[ $VAR = +([a-zA-Z]) ]]
then
....
else
...
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2002 12:42 PM
05-22-2002 12:42 PM
Re: number or letter
This one should do it
read ANSWER
if [$ANSWER != [0-9]]
then
echo "Enter a Number"
else
echo "Good Answer"
fi
The positive situation would be
read ANSWER
if [$ANSWER = [0-9]]
then
echo "Good Answer"
else
echo "Enter a Number"
fi
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2002 01:19 PM
05-22-2002 01:19 PM
Re: number or letter
This is one method:
#!/usr/bin/sh
typeset X=$1
if [ `expr "$X" : '[0-9,\-]*'` -ne `expr "$X" : '.*'` ]
then
echo "not a number!"
else
echo "ok, is a number!"
fi
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2002 02:28 PM
05-22-2002 02:28 PM
Re: number or letter
#!/usr/bin/ksh
echo "Enter something :"
read my_value
# the next statement will return a value zero providing its numeric
let new_value=$my_value
if [[ $? -eq 0 ]] ; then
echo "ok its an integer"
else
echo "failed the test"
fi
John.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2002 07:38 AM
05-23-2002 07:38 AM
Re: number or letter
If you are looking at number letters versus everything else, how about a case statement (it uses file name generation):
case ${ANSR}
in
[0-9]) echo Number
;;
[!0-9]) echo Not a number
;;
*) echo not sure what I got
;;
esac
If you are looking for numbers that are not a single digit integer, you would need to formulate a regular expression and use some other program for the text. Here is an extended regular expression that matches numbers (signed and floating point, too):
^(\+|-)?[0-9]*\.?[0-9]+$
-dlt-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2002 11:23 AM
05-23-2002 11:23 AM
Re: number or letter
If you're expecting only a numberic response, why not force the variable to be an integer?
typeset -i rval=0
Any attempt to assign a string to it will fail.
This can also be used to help distinguish between alpha and numeric responses:
typeset -i rval=0
read answer
if ( rval=$answer )
then
echo numeric
else
echo alpha
fi