- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to evaluate a ?: operator from a shell scr...
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
06-04-2002 11:52 PM
06-04-2002 11:52 PM
How to evaluate a ?: operator from a shell script
(A>B+1)?C+2:D
from a shell script without creating a shell function for parsing.
note: A, B, C and D are shell environment variables.
Can anyone help me ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 11:58 PM
06-04-2002 11:58 PM
Re: How to evaluate a ?: operator from a shell script
Use the if-then-else construct:
#!/usr/bin/sh
if [ "$A" -gt "$B" ]
then
result=`expr $C + 2`
else
result="$D"
fi
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2002 12:03 AM
06-05-2002 12:03 AM
Re: How to evaluate a ?: operator from a shell script
Should be as follows:
#!/usr/bin/sh
temp=`expr $B + 1`
if [ "$A" -gt "$temp" ]
then
result=`expr $C + 2`
else
result="$D"
fi
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2002 12:04 AM
06-05-2002 12:04 AM
Re: How to evaluate a ?: operator from a shell script
Check out the following construction:
if [ "$A" -gt `expr $B + 1` ]
then
value=`expr $C + 2`
else
value="$D"
fi
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2002 01:38 AM
06-05-2002 01:38 AM
Re: How to evaluate a ?: operator from a shell script
Supose user types the ?: expression, i.e., I don't know the expression in advance.
In the previous example, A, B, C and D are symbolic names for numerical values or environment variables. My script has no A, B, C or D variable names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2002 02:13 AM
06-05-2002 02:13 AM
Re: How to evaluate a ?: operator from a shell script
Then you need to write a parser script language just for that, probably invent a new shell interpreter that does that. :)
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2002 09:31 AM
06-05-2002 09:31 AM
Re: How to evaluate a ?: operator from a shell script
the shell (well, at least Bourne, Korn, POSIX) does not have the C-style operator "?:"!
If you really need to use that operator, why not use a C-interpreter?
There do exist some OpenSource implementations...
Regards,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2002 09:52 AM
06-05-2002 09:52 AM