- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- In shell script ,how to check if type of a shell v...
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
01-22-2002 12:19 PM
01-22-2002 12:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 12:24 PM
01-22-2002 12:24 PM
Re: In shell script ,how to check if type of a shell variable is integer ?
The first usage of a variable determines its usage. *However* if you want to declare a variable as an integer, do:
# typeset -i N
This declares N as an integer, making arithmetic much faster.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 12:55 PM
01-22-2002 12:55 PM
Re: In shell script ,how to check if type of a shell variable is integer ?
I think that ususally the person writing the script knows what form their data will be in and thus they will apply the interger or string comparision format to their test, i.e.
a = a or 1 -eq 1, I know of no check directly, if you are concerned then you could run a = and -eq test to see which works and determine it that way. Obviously not the most efficent way to code, but..
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 01:18 PM
01-22-2002 01:18 PM
Re: In shell script ,how to check if type of a shell variable is integer ?
Here is a simple shell function that can be included to test to see if a variable is a valid integer. e.g. -1, 1234, 563 return 0 (good) but
12-34, 12.34, abc return 1 (bad).
Use it in your script like this:
var1=123
is_integer ${var1}
INTSTAT=$?
if [ ${INTSTAT} -eq 0 ]
then
echo "Good"
else
echo "Bad"
fi
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 01:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 01:21 PM
01-22-2002 01:21 PM
Re: In shell script ,how to check if type of a shell variable is integer ?
One way to test a variable is this:
if [ `expr $VAR : '[0-9]*'` -eq `expr $VAR : '.*'` ]
then
echo "$VAR is an integer"
else
echo "$VAR is not an integer"
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 01:33 PM
01-22-2002 01:33 PM
Re: In shell script ,how to check if type of a shell variable is integer ?
Thanks a lot. That's what I want. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2002 03:23 PM
01-22-2002 03:23 PM