- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- What is 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
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
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
тАО04-05-2011 07:39 AM
тАО04-05-2011 07:39 AM
can anyone tell me the true definition of an integer? My understanding is that is a whole number derived from a mathematical sum - info I found of the web:
"An integer is what is more commonly known as a whole number. It may be positive, negative, or the number zero, but it must be whole. In some cases the definition of whole number will exclude the number zero, or even the set of negative numbers, but this is not as common as the more inclusive use of the term. Integers are the numbers people are most familiar with, and they serve a crucial role in virtually all mathematics."
The reason I ask this question is because I want to know what is the correct syntax when using a test statement ie:
is set MyVar=0 and to test this I would:
if [ ${MyVar} = "0" ]; the
true
etc etc
however if I created a sum or a count:
count=0
while [ ${count} -lt 10 ]; do
etc etc
(( count =+ ))
I understand that using "= != < >" is for testing a string so substituting MyVar=0 does "0" become a string.
Thanks
Chris
Solved! Go to Solution.
- Tags:
- integer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 07:50 AM
тАО04-05-2011 07:50 AM
Re: What is an integer?
if you have difficulties with expressions, consult the man page:
# man test
or
# man ksh
can also help you, search for the keywords "while", "for" or "if". If you are using other shell look at its man page.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 07:52 AM
тАО04-05-2011 07:52 AM
Re: What is an integer?
that's because the shell is auto-converting the value.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 07:57 AM
тАО04-05-2011 07:57 AM
Solution> I understand that using "= != < >" is for testing a string so substituting MyVar=0 does "0" become a string.
Yes, I believe so.
In the shell, you can declare an integer (as opposed to a string) with the 'typeset -i' declaration. This speeds up arithmetic operations.
In 'awk' programs you will sometimes see someone do:
# awk '{$1+0 ...
...which prevents you from doing silly arithmetic with non-numeric data. Compare these results:
# echo FF | awk '{SUM=($0+0);print SUM}'
# echo FF | awk '{SUM=($0);print SUM}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 08:08 AM
тАО04-05-2011 08:08 AM
Re: What is an integer?
As I thought but wanted the experts to confirm
8-)
root:/scratch #echo FF | awk '{SUM=$0+0);print SUM}'
0
root:/scratch #echo FF | awk '{SUM=($0);print SUM}'
FF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 10:45 PM
тАО04-06-2011 10:45 PM
Re: What is an integer?
In the shell, an integer is something that's not a string. (And not a floating point number for shells that support those types.)
>if [ ${MyVar} = "0" ]; then
This is a string comparison. If you know MyVar is an integer or numeric you should do:
if [ $MyVar -eq 0 ]; then
Or even:
if (( Myvar == 0 )); then
>while [ ${count} -lt 10 ]; do
Or:
while (( count < 10 )); do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 10:56 PM
тАО04-06-2011 10:56 PM
Re: What is an integer?
typeset -i MyVar=0
if (( MyVar = 0 )); then
true
etc etc
typeset -i count=0
while (( count < 10 )); do
etc etc
(( count =+ ))