- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how do I convert this to a number?
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
04-09-2003 06:52 AM
04-09-2003 06:52 AM
for var in $list ; do
if $var -gt 0 || $var -lt 200;then
...do stuff...
fi
done
I am getting syntax error (I think its' because $var is not a number) Can one of you experts please help? Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 06:57 AM
04-09-2003 06:57 AM
Re: how do I convert this to a number?
if [ $var -gt 0 && $var -lt 300 ]; then
...do stuff...
fi
And it gives me syntax error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 06:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 06:59 AM
04-09-2003 06:59 AM
Re: how do I convert this to a number?
Try
typeset -i var
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 07:01 AM
04-09-2003 07:01 AM
Re: how do I convert this to a number?
Change the '&&' to '-a'. See the 'test' man pages. The binary AND operator is '-a'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 07:05 AM
04-09-2003 07:05 AM
Re: how do I convert this to a number?
Double brackets accept "||" as "or".
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 07:10 AM
04-09-2003 07:10 AM
Re: how do I convert this to a number?
You need to enclose the "$var -gt 0 || $var -lt 200" expression like "[[ $var -gt 0 || $var -lt 200 ]]"
Since the [[ and ]] are considered keywords by the shell, there must be a space between the opening [[ and $var. There must also be a space between 200 and ]].
--
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 08:02 AM
04-09-2003 08:02 AM
Re: how do I convert this to a number?
I read somewhere in the forums the following -
The difference between using '[[' and '[' to specify the conditions is that while '[[', ']]' are shell builtin operators the '[' and ']' operators are not.
So, for optimal performance use '[[' and ']]' to specify conditions.
- ramd
'as an aside'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2003 09:14 AM
04-09-2003 09:14 AM
Re: how do I convert this to a number?
Thanks for your prompt replies.
Rodney's response worked just fine. But I also learned new things from everyone else's response. So thank you, and of course points for everyone!