- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: typeset question?
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
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
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
тАО02-18-2006 07:56 PM
тАО02-18-2006 07:56 PM
typeset question?
Can you advice why I can not echo the full value of $input?
typeset -i input
print "Enter numbers? \c"
read input > /dev/null 2>&1
echo $input (it returns 0 ??)
10 points for best solution!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2006 08:08 PM
тАО02-18-2006 08:08 PM
Re: typeset question?
man sh-posix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2006 08:13 PM
тАО02-18-2006 08:13 PM
Re: typeset question?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2006 08:54 PM
тАО02-18-2006 08:54 PM
Re: typeset question?
But as i recall, there is option to set the lengthofa variable set with typeset.
Something like like typeset -i10 input.
This will acceptonly numbers less than or eqalto10 digits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2006 11:58 PM
тАО02-18-2006 11:58 PM
Re: typeset question?
I haven't an HP-UX box to try it on, but your script works fine on cygwin ksh and Linux bash.
By the way, the argument, -i, allows you to specify what BASE the number will be, not it's length. The default should be base10.
How big of a number are you trying? I suspect that it needs to be no bigger than 31 or 32-bit numbers, and probably is very platform dependent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 01:27 AM
тАО02-19-2006 01:27 AM
Re: typeset question?
try inserting the path to the shell interpreter, e.g.:
$ cat ./readme.sh
#!/usr/bin/sh
typeset -i input
print "Enter numbers? \c"
read input > /dev/null 2>&1
echo "$input"
If your script always returns 0, it sounds as if it does not accept any input at all. However, it works well over here, e.g.:
$ ./readme.sh
Enter numbers? 2147283648
2147283648
but if you try numbers bigger than the above, 2^32-1, the result of the operation is undefined.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 02:58 AM
тАО02-19-2006 02:58 AM
Re: typeset question?
Perhaps you want :
typeset -Z input
...instead of reading the input into a variable typeset with '-i'. The '-Z' says right-justify and fill with leading zeros.
Beware of doing arithmetic with leading zeros. if UNIX95 is set, for instance, a leading zero signals octal and a leading 0x signals hexadecimal base.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 04:59 AM
тАО02-19-2006 04:59 AM
Re: typeset question?
I think it's my fault that I didn't mention the number I'm trying to echo is in a form of octets. xx.xx.xx.xx? The $input variable always returns zero?
but if I enter numbers with no dots it echos correctly but that's not what I want anyway?
James,
"typeset -Z input" accept alphanumeric varialbls? I want it to accept numbers only with dots between them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 05:11 AM
тАО02-19-2006 05:11 AM
Re: typeset question?
you cannot do that by just defining af variable; you have to use other tools, e.g.:
#!/usr/bin/sh
typeset -Z input
print "Enter numbers? \c"
read input > /dev/null 2>&1
CHECK1=$(echo "$input" | tr -d \.)
CHECK2=$(echo "$CHECK1" | tr -d [:digit:])
if [ "$CHECK2" = "" ]
then
echo "$input"
else
echo illegal input
fi
~
regards,
John K.~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 05:36 AM
тАО02-19-2006 05:36 AM
Re: typeset question?
You must rethink your use of typeset in this case. You may just want to omit typeset altogether.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 07:49 AM
тАО02-19-2006 07:49 AM
Re: typeset question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 12:40 PM
тАО02-19-2006 12:40 PM
Re: typeset question?
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 01:08 PM
тАО02-19-2006 01:08 PM
Re: typeset question?
I want it to read numbers only with dots and then echo the full input. That's all.
Any examples?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 03:11 PM
тАО02-19-2006 03:11 PM
Re: typeset question?
print "Enter numbers? \c"
read
echo "$REPLY"
The read statement reads everything on the line and if no variable is specified, then everything is assigned to REPLY. You use a variable with mixed characters by surrounding it with double quotes.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2006 05:13 PM
тАО02-19-2006 05:13 PM
Re: typeset question?
print "Enter numbers? \c"
read input > /dev/null 2>&1
echo $input
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 11:20 AM
тАО02-24-2006 11:20 AM