- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: no negation in if-clause constructs of ksh?
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
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
тАО11-10-2000 12:47 AM
тАО11-10-2000 12:47 AM
no negation in if-clause constructs of ksh?
I guess this one should be an easy 10 pointer.
I usually prefer Perl or Bourne shell as scripting languages of 1st choice.
Thus I'm not too familiar with the Korn shell's obscurities and idiosyncracies.
I only accidentally stumbled over this (to me) odd behaviour while I made an additional entry to a user's .profile who happens to have ksh as login shell.
The entry I initially made was something like this, knowing this should work in sh:
if ! echo $PATH|grep -q sbin; then
PATH=${PATH}:/usr/sbin
fi
Amazingly, ksh didn't seem to be happy with the negatory bang.
Of course, as with grep this could easily be overcome by removing the bang and inserting grep's -v flag in the if-clause.
But I was quite puzzled to learn from HP's ksh manpage that my intended kind of negation isn't reflected for ksh.
OK, there isn't a real need for ksh since HP's sh is a Posix Bourne shell which adopted most of the additional features of ksh (e.g. arrays, extended variable substitutions etc.), and when I'm in need of advanced data structures (i.e. LoLs) I would always go for Perl.
But this arouse my curiosity, and I wonder if ksh isn't just using a different syntax I might have missed.
Regards
Ralph
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2000 01:24 AM
тАО11-10-2000 01:24 AM
Re: no negation in if-clause constructs of ksh?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2000 01:28 AM
тАО11-10-2000 01:28 AM
Re: no negation in if-clause constructs of ksh?
echo $PATH|grep -q sbin
if [ $? != 0 ] ; then
PATH=${PATH}:/usr/sbin
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2000 01:47 AM
тАО11-10-2000 01:47 AM
Re: no negation in if-clause constructs of ksh?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2000 01:56 AM
тАО11-10-2000 01:56 AM
Re: no negation in if-clause constructs of ksh?
echo $PATH|grep -q sbin && PATH=${PATH}:/usr/sbin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2000 02:18 AM
тАО11-10-2000 02:18 AM
Re: no negation in if-clause constructs of ksh?
What you suggested is all familiar to me.
Of course, do I know the logical concatantion of commands (viz. &&, ||).
Actually in Perl this is sort of standard fare, especially with || to warn, die, croak etc.
Also the test of the last statement's exit code through $? is familiar to me, but seems a little clumsy instead of a single test.
From what I conclude from HP's ksh manpage it really seems to be the case that in ksh you only may use ! is in a test construct (i.e. test command or its alias []).
Why haven't they (i.e. ksh's developers) adopted the valid ! use as in the Bourne shell.
E.g. excerpt from sh-posix manpage:
...
A pipeline is a sequence of one or more commands separated by a bar (|) and optionally preceded by an exclamation mark (!)
...
If ! does not precede the pipeline, the exit status of the pipeline is the exit status of the last command in the pipeline.
Otherwise, the exit status of the pipeline is the logical negation of the exit status of the last command in the pipeline.
...
I cannot find such a statement in the ksh manpage :-(