Operating System - HP-UX
1752795 Members
5484 Online
108789 Solutions
New Discussion юеВ

Re: property of Korn shell and POSIX shell

 
Billa-User
Regular Advisor

property of Korn shell and POSIX shell

I have questions about Korn shell and POSIX shell:

i read thread : "best shell for writing a shell script"

http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1228469331024+28353475&threadId=994216

One meaning is : "The Korn shell and POSIX shell are all but identical"

i found a little difference (because a colleague made a shell-script test under Linux):

i tested following script test.sh (HPUX 11.11, 11.31):
#BEGIN :xxxxxxxxxxxxxxxxxxxxxxxxx
test_proc ()
{
echo $(basename $0)
}

test_proc
#END: xxxxxxxxxxxxxxxxxxxxxxxxx

Test with "Korn shell" #!/usr/bin/ksh

+ test_proc
+ basename test_proc
+ echo test_proc
test_proc

Test with "POSIX shell" #!/sbin/sh or #!/usr/bin/sh

+ test_proc
test.sh

Test with "Korn shell" #!/usr/bin/ksh
didn't return the script name "test.sh". it returned the procedure name "test_proc".

POSIX shell returned the right value.
LINUX "Korn shell" returned also the right value.

In our company the standard shell is "Korn shell" because years ago "!/bin/sh" didn't have the same features like "Korn shell" .

So what SHELL should we use ? or is this a bug of HPUX "Korn shell" ?

We have the meaning "Korn shell" was the best shell for shell's for HPUX, LINUX.

Now POSIX Shell of HPUX is better ?
13 REPLIES 13
Hemmetter
Esteemed Contributor

Re: property of Korn shell and POSIX shell

Servus,


from ksh(1)

Command Substitution

However, command substitution of a function creates a separate process to execute the function and all commands (built-in or otherwise) in that function.


from sh-posix(1)

Functions

Functions execute in the same process as the caller and share all files and current working directory with the caller.

######################################

They both return a right value i a term of their man-page.

The answer which shell is better will spark of a flame war.

The best shell is the one you get along best.


HGH
Fredrik.eriksson
Valued Contributor

Re: property of Korn shell and POSIX shell

Agreed, the best shell is the one you're most comfortable in (or in a company environment, the one that most people like or all scripts are written for :P).
If you know POSIX shells better then you know the other ones that's the one you should use.
If Korn is your prefered way then use that one :)

The feature of being able to choose which shell you use is just for this reason.

I myself is BASH user :) but that's mostly because I've grown up using Linux where it's pretty much default :P

Best regards
Fredrik Eriksson

Re: property of Korn shell and POSIX shell

>> The best shell is the one you get along best

Except csh

csh is *never* the best shell! ;o)

Duncan

I am an HPE Employee
Accept or Kudo
James R. Ferguson
Acclaimed Contributor

Re: property of Korn shell and POSIX shell

Hi:

I like Hemmetter's response: "The answer which shell is better will spark a flame war."

I think the following should answer your question:

1. For HP-UX, anything that needs to run at startup *must* be written in the standard HP Posix shell using the statically linked binary '/sbin/sh' as I noted in the thread you reference. Period; no choice involved.

2. For very *similar* shells like 'ksh' [where by default this is the Korn88 implementation, not the Korn93 version found in '/usr/dt/bin/dtksh'], you need to be cognizant of subtle differences as you has seen. This becomes important when *porting* a script to different platforms where '/bin/sh' may be the Posix shwll or the Korn shell, or the Bash shell by default.

3. When you want certain features, and I like those that Korn93 adds, you must *choose* while being aware what your choices will mean should you have to move the script to another environment.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: property of Korn shell and POSIX shell

>Now POSIX Shell of HP-UX is better?

It depends. The POSIX shell is standard and standard is better than better.

One advantage of ksh is that it has 64 bit integer arithmetic vs only 32 for sh. And ksh93 has floating point.
~sesh
Esteemed Contributor

Re: property of Korn shell and POSIX shell

HP-UX uses the POSIX shell as the default shell. Which shell you use, depends on how comfortable with it.

There could be some differences in how shell handles commands or their variables (options), and hence change the output.

For more information about the features of the Korn (ksh) and POSIX (sh) & their comparison with other shells...
http://docs.hp.com/en/B2355-90046/ch15s03.html
OldSchool
Honored Contributor

Re: property of Korn shell and POSIX shell

Dennis said "The POSIX shell is standard and standard is better than better" which I agree with.

you will find that the Debian Linux adherants use the Debian Almquist Shell (aka dash) and some claim it complies with a newer POSIX std.

I tend to use ksh, simply because widely available and is std compliant. To me, its easier to work within it than to write something that uses some feature that won't work when I have to port it.
Bill Hassell
Honored Contributor

Re: property of Korn shell and POSIX shell

> In our company the standard shell is "Korn shell" because years ago "!/bin/sh" didn't have the same features like "Korn shell" .

Outside HP-UX, /bin/sh is called the Bourne shell and is not POSIX compliant. It is definitely limited and not recommended for today's scripting. Unfortunately, HP's POSIX shell is called /bin/sh (ie, /usr/bin/sh) and is often confused with the Bourne shell. The Korn shell is one of several POSIX compliant shells. The POSIX standard is independent of the flavor of Unix so it provides a base for standard shell scripting. BASH is another POSIX shell in addition to HP's POSIX shell. Here are some useful references:

http://en.wikipedia.org/wiki/Bash
http://en.wikipedia.org/wiki/Korn_shell
http://en.wikipedia.org/wiki/Bourne_shell

Every shell, even ksh, has implementation differences. As mentioned HP's ksh is actually ksh-1988 while the dtksh shell (found in /usr/dt/bin/dtksh) is ksh-1993. And the 1993 version of ksh is superset of ksh-1988.

So there will be differences. And even ksh-1988 will have obscure differences within HP-UX depending on patches (which is the case with Linux, Solaris, AIX, etc). So script writing must be restricted for portability. Also, many scripts written for system administration are completely non-portable because many commands (ie, programs) are completely unique (such as ioscan for HP-UX).

What this means is that script writers should be aware that differences will exist and they must be tested in each environment.


Bill Hassell, sysadmin
Billa-User
Regular Advisor

Re: property of Korn shell and POSIX shell

hello,

thank you to all for the useful informations.

why isn't the standard "korn shell" of HPUX Korn93 ? can i use Korn93 version '/usr/dt/bin/dtksh'?

i have to change a central programm tool (included shell scripts with source code about 700-800 lines per script), which was implemented years ago.

i have been changing to POSIX shell and the scripts use "set -e". one effect is now when variable not initialized and in the source code exists : "unset VARIABLE" the shell script got an error and stop.

with Korn93 i have now problems ...
yes i know the style of the scripts could be better.

the programm tool have been worked for many years with "Korn Shell", so i think it is better for me to use "Korn93" ?