- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh: if statement negation and arithmetic evaluati...
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
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
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-19-2013 09:27 AM - edited 02-20-2013 01:15 PM
02-19-2013 09:27 AM - edited 02-20-2013 01:15 PM
Hello,
I use KSH Version M-11/16/88f with HP-UX 11.31.
How can use in a "if statement" with a "function" the negation .
Only this works with ":"
if ( function "${parameter1}" ) then : else cmd1 cmd2 .. fi
i get an error when i use "!" to negate :
if ! ( function "${parameter1}" ) then cmd1 fi
syntax error at line XXX : `(' unexpected
second question : when i want to check if the sum of two numbers is lower then another number ,
then i use this :
n1=10 n2=10 max_n=40 if [ $(( ${n1} + ${n2} )) -le ${max_n} ] then echo ok fi
i tested with input of this thread :
if statement negation and Arithmetic evaluation
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2013 11:22 PM - edited 02-19-2013 11:30 PM
02-19-2013 11:22 PM - edited 02-19-2013 11:30 PM
Solution>How can use in a "if statement" with a "function" the negation .
You can't use ksh 88 with that "!". You must use ksh 93 (dtksh) or the Posix shell.
>if ! ( function "${parameter1}" )
This works fine in the Posix shell, sh.
Also, you shouldn't be using those (...), that creates a subshell.
If you like some type of balanced punctuation, you can use:
if ! { function "${parameter1}"; } then
>when I want to check if the sum of two numbers is lower then another number,
Your code works, what was your question?
But it would look better if you switched to arithmetic expressions:
if (( n1 + n2 <= max_n )); then
>I tested with input of this thread :
if statement negation and Arithmetic evaluation
Your hyperlink isn't valid. It is missing a ":" after "http".
You should be able to use Post Options > Edit Reply, to correct it. (I fixed my copy.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2013 01:16 PM
02-20-2013 01:16 PM
Re: ksh: if statement negation and arithmetic evaluation
hello,
thx a lot and i corrected it
regards