- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Validations for read?
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
10-12-2002 09:18 PM
10-12-2002 09:18 PM
script1.sh
-----------
echo "Enter a number: \c"
read num1
i want to only num1 accepts number (ex: 1, 2, 4). But if i enter (enter key, backspace key, spacebar key). The output will be different. Any sample validations to avoid this. Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2002 10:43 PM
10-12-2002 10:43 PM
Re: Validations for read?
if [[ $num1 == [:alnum:] ]] ;then
but it probably doesn't, so you'll need to do something like this
if [[ $num1 == [a-zA-Z0-9] ]] ;then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2002 10:49 PM
10-12-2002 10:49 PM
Re: Validations for read?
[:digit:] or [0-9]
hex numbers
[:xdigit:] or [0-9a-fA-F]
just certain digits
[159] etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2002 02:58 AM
10-13-2002 02:58 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2002 05:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2002 08:36 AM
10-13-2002 08:36 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 04:44 AM
10-14-2002 04:44 AM
Re: Validations for read?
typeset -i num1
It error out on anything other than a number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 04:48 AM
10-14-2002 04:48 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 04:50 AM
10-14-2002 04:50 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 04:53 AM
10-14-2002 04:53 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 04:58 AM
10-14-2002 04:58 AM
Re: Validations for read?
The 'typeset' command is part of the shell. You can find out about it in the man pages for 'ksh' and 'sh-posix', just search for typeset.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:16 AM
10-14-2002 07:16 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:25 AM
10-14-2002 07:25 AM
Re: Validations for read?
Here is a quick sample of using typeset that I put together. This sample fills the variable with zeros:
>cat typeset.test.ksh
#!/bin/ksh
# typeset.test.ksh
typeset -Z8 zeros=0
echo "zeros is $zeros"
zeros=123
echo "zeros is $zeros"
>./typeset.test.ksh
zeros is 00000000
zeros is 00000123
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:44 AM
10-14-2002 07:44 AM
Re: Validations for read?
until [ "$answer" = [:digit:] ] ; do
echo " Answer with a number !\c"
read answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:47 AM
10-14-2002 07:47 AM
Re: Validations for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:48 AM
10-14-2002 07:48 AM
Re: Validations for read?
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:52 AM
10-14-2002 07:52 AM
Re: Validations for read?
The output:
-----------
enter a number
Answer with a number!1
Answer with a number!b
Answer with a number!3
endless loop
It seems like cannot work to me. Anyway thanks for your help. Do i need to replace :digit: to :4: or :1:???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 07:55 AM
10-14-2002 07:55 AM
Re: Validations for read?
[0-9]