incompatibilities between ksh and sh
David Korn
dgk at ulysses.UUCP
Wed Jun 13 00:56:21 AEST 1984
KSH VS. SH
I have not made a complete comparison between S5R2 /bin/sh and ksh. A
direct comparison of the manuals may uncover more incompatibilities than
I have listed here. In addition, I have omitted some incompatibilities
that are bugs in S5R2 sh that may have been fixed for S5R2. I have
also omitted incompatibilities in cases that sh clearly is incorrect,
such as in cases where it core dumps. I have also omitted cases which
are bugs in ksh. I have also omitted built-ins since this can be circumvented
by using the alias facility if necessary.
The following is a list of known incompatibilities between ksh and sh:
1. The IFS parameter is only effective for set, for and read in ksh.
Thus, IFS=x;exit will execute e on the file it with sh but will
exit with ksh.
2. If an environment parameter is modified by ksh, the new value
will be passed to the children. In sh you must export the
parameter for this to happen.
3. Time is a reserved word in ksh. Thus time a | b will time the
pipeline in ksh while only a will be timed with sh. You can
also time built-in commands and functions with ksh, you can't
with sh.
4. Select and function are reserved words in ksh.
5. Parameter assignments only have scope for the command or function
they precede in ksh. In sh, built-in commands and functions
treat parameter assignments as globals. (Notice that S5R2 and
S5R1 treat parameter assignments to pwd and echo in an
incompatible way).
6. The output of some built-in commands and error messages is different
in a few cases, for example times produces two lines of output in ksh.
7. While loops with redirection are not executed in a separate process
in ksh so assignments made within loops remain in effect after the
loop completes.
8. The semantics of functions are somewhat different. Ksh can have
local variables and allow recursive functions. Errors in functions
abort the function but not the script that they are in.
9. The name space for functions and variables is separate in ksh. In
/bin/sh they share the same space. The unset builtin requires
a -f flag to unset a function in ksh.
10. Words that begin with ~ may be expanded in ksh. Sh does not have
this feature.
11. The character ^ is not special in ksh. In sh it is an archaic
synonym for |.
12. Whenever (( occurs where a command name is valid, ksh assumes
that an arithmetic expression follows. In sh this means a
sub-shell inside a sub-shell.
13. Non-blank contiguous IFS delimiters generate a null input argument.
Therefore, you can use IFS=: and correctly read the /etc/profile
file even when fields are omitted. In sh, multiple delimiters
count as a single delimiter.
14. Arithmetic test comparison operators (-eq, -lt, ...) allow any
arithmetic expressions. Sh allows only constants. If you say
test x -eq 0 in sh, which is meaningless, it returns true, but
in ksh it depends on the value of the variable x. If there
is no variable x, then ksh produces an error message.
15. The environment handed down to a program is not sorted in ksh.
A user should not reply in this quirk of sh since any user
program can provide an environment list which does not have
to be sorted. (Getenv(3) does not assume a sorted list).
16. There is an alias hash in ksh which does what the S5R2 has
built-in does except for the -r flag. In ksh, you must say
PATH=$PATH to achieve the same result.
17. The expansion of "$@" with no arguments produces the null string
in the Bourne shell and produces nothing with ksh when there are
no arguments. I am not sure whether this is a bug in the Bourne
shell or intentional. The manual page leads me to think that it
is a bug.
I am interested in expanding this list so please let me know if you
uncover any others.
David Korn
ulysses!dgk
More information about the Comp.unix
mailing list