- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Can not seem to get this IF statement to work
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
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
тАО12-21-2004 05:05 AM
тАО12-21-2004 05:05 AM
$WCPU = 0.48
$HIGHWATER 0.10
$COUNTER 1
I want to do something like this
If $WCPU is greater than or equal to $HIGHWATER AND $COUNTER is equal to 0 then do something.
I've tried if [$WCPU -ge $HIGHWATER -a $COUNTER -eq 0] but it doesn't work. I get
./toptest.sh[23]: [0.48: not found.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:14 AM
тАО12-21-2004 05:14 AM
Re: Can not seem to get this IF statement to work
Try [[ $WCPU -ge $HIGHWATER -a $COUNTER -eq 0 ]]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:14 AM
тАО12-21-2004 05:14 AM
Re: Can not seem to get this IF statement to work
if [ $WCPU -ge $HIGHWATER -a $COUNTER -eq 0 ]
From your error message, it appears the shell is trying to evaluate [$WCPU as a command.
Also, AFAIK, ksh can only handle integers in variables for purposes of determining greater than and less than. It will evaluate 0.48 and 0.10 as 0 in the if statement. You may want to change your numbering to use integers instead.
-JWJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:22 AM
тАО12-21-2004 05:22 AM
Re: Can not seem to get this IF statement to work
What are you suggesting I do with my variables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:25 AM
тАО12-21-2004 05:25 AM
Re: Can not seem to get this IF statement to work
Isn't this similar to the problem you had a while back:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=737698
To quote Clay, "The problem is that the shell only does integer arithmetic. Use awk or bc."
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:28 AM
тАО12-21-2004 05:28 AM
Re: Can not seem to get this IF statement to work
For example, if you define the variables as so:
WCPU=48
HIGHWATER=10
then it will work. If you're getting the $WCPU value from another command or a script, you may need to convert it, by removing the decimal point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:32 AM
тАО12-21-2004 05:32 AM
Re: Can not seem to get this IF statement to work
I believe that is in the same ball park. I had forgetten about that thread. I quickly manned bc and I found it does not currently support && or ||. Also, I'm not clear on it usage in my if statement.
If you have done anything like this before, I would enjoy seeing some examples.
Thanks again for refreshing my memory.
Scott
- Tags:
- bc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 05:38 AM
тАО12-21-2004 05:38 AM
Re: Can not seem to get this IF statement to work
I'm not all that great on shell scripting myself - I only stumbled over that thread while I was searching the ITRC for a solution to your problem.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 06:31 AM
тАО12-21-2004 06:31 AM
Re: Can not seem to get this IF statement to work
if you format wcpu and highwater the same way you can compare them as strings.
WCPU=`printf %06.2f 0.48`
HIGHWATER==`printf %06.2f 0.10`
if [ "$WCPU" > "$HIGHWATER" ]..
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 09:52 AM
тАО12-21-2004 09:52 AM
Re: Can not seem to get this IF statement to work
NCPU=(( "$WCPU" * "100" ))
NHIGHWATER=(( "$HIGHWATER" * "100" ))
if test "$NHIGHWATER" -eq "$NCPU" -a "$COUNTER1" -eq "0"
then
do something
fi
The double parenthesis is ksh's version of the "let" statement.