- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- looking for a shorten if...then... ksh statement.
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-25-2004 10:25 AM
06-25-2004 10:25 AM
looking for a shorten if...then... ksh statement.
if [[ `uname -r` = "B.11.11" ]]; then
echo "I'M 11.11"
else
echo "I'm 11.0"
fi
Now, for some reasons, I have to make the if/then/else statement short, and I remember there is a way to achieve that withought using if/the/else statement. I just can not remember it now.
Something like: (`uname -r` ?; | B.11.11; echo "I'm 11.11|...). Again, I can not recall what exactly the statement is.
Please help me out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2004 10:30 AM
06-25-2004 10:30 AM
Re: looking for a shorten if...then... ksh statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2004 10:31 AM
06-25-2004 10:31 AM
Re: looking for a shorten if...then... ksh statement.
simply
[[ `uname -r` = "B.11.11" ]] && echo "im 11.11" || echo "im 11.00"
Regards
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2004 10:31 AM
06-25-2004 10:31 AM
Re: looking for a shorten if...then... ksh statement.
[[ $(uname -r) = "B.11.11" ]] && echo "I'M 11.11" || echo "I'm 11.0"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2004 12:29 AM
06-26-2004 12:29 AM
Re: looking for a shorten if...then... ksh statement.
This works for me on all versions 10.x,11.x
# uname -r | echo "This version is HPUX `cut -d "." -f 2-3`"
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2004 11:42 PM
06-27-2004 11:42 PM
Re: looking for a shorten if...then... ksh statement.
the solutions
cmd && echo ok || echo failed
are ok. But keep in mind, that this is only
the case, when the second command ('echo ok')
never fails!
If your question was just a common example,
keep in mind, that something like this
cmd && false || echo something
will execute 'false' AND echo 'something' -
since the commans before the '||' failed!
A command sequence like
[ -d dir ] || mkdir dir && echo re-using dir
will do the echo, even if 'dir' was just created.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2004 08:26 AM
06-29-2004 08:26 AM
Re: looking for a shorten if...then... ksh statement.
I actually wanted to run this entire statement on the remote server by using ssh:
ssh remoteserver â [[ `uname â r` = â B.11.11 ]] && CMD1_on_remote || CMD2_on_remoteâ
However, my questions is when I run uname â r, is this command really running on local or remote site?
I want to run CMD1 and CMD2 on remote site, based on the different version of uname â r on remote site.
It doesnâ t seem to b
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2004 08:33 AM
06-29-2004 08:33 AM
Re: looking for a shorten if...then... ksh statement.
ssh remoteserver "[[ `uname -r` = "B.11.11" ]] && CMD1_on_remote || CMD2_on_remote"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2004 08:34 AM
06-29-2004 08:34 AM
Re: looking for a shorten if...then... ksh statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2004 09:39 AM
06-29-2004 09:39 AM
Re: looking for a shorten if...then... ksh statement.
I wouldn't try shell's built-in commands with remsh and ssh. You could try escaping the quotes and all but here is the easy way.
ssh remotehost "uname -r |grep -q B.11.11 && CMD1_onremote || CMD2_onremote"
-Sri