1*35113Smarc 2*35113Smarc KSH-I VS. SH 3*35113Smarc 4*35113Smarc 5*35113Smarc 6*35113SmarcI have not made a complete comparison between 5.2 /bin/sh and ksh-i. A 7*35113Smarcdirect comparison of the manuals may uncover more incompatibilities than 8*35113SmarcI have listed here. In addition, I have omitted some incompatibilities 9*35113Smarcthat are bugs in 5.0 sh that may have been fixed for 5.2. I have 10*35113Smarcalso omitted incompatibilities in cases that sh clearly is incorrect, 11*35113Smarcsuch as in cases where it core dumps. I have also omitted cases which 12*35113Smarcare bugs in ksh-i. I have omitted built-ins in ksh-i which are not in /bin/sh 13*35113Smarcsince this can be circumvented by using the alias facility if necessary. 14*35113Smarc 15*35113SmarcThe following is a list of known incompatibilities between ksh-i and sh: 16*35113Smarc 17*35113Smarc1. The IFS parameter is only effective for the read built-in and 18*35113Smarc after parameter and command substitution in ksh-i. Thus, IFS=x; 19*35113Smarc exit will execute e on the file it with sh but will exit with ksh-i. 20*35113Smarc 21*35113Smarc2. If an environment parameter is modified by ksh-i, the new value 22*35113Smarc will be passed to the children. In sh you must export the 23*35113Smarc parameter for this to happen. 24*35113Smarc 25*35113Smarc3. Time is a reserved word in ksh-i. Thus time a | b will time the 26*35113Smarc pipeline in ksh-i while only a will be timed with sh. You can 27*35113Smarc also time built-in commands and functions with ksh-i, you can't 28*35113Smarc with sh. 29*35113Smarc 30*35113Smarc4. Select and function are reserved words in ksh-i. 31*35113Smarc 32*35113Smarc5. Parameter assignments only have scope for the command or function 33*35113Smarc they precede in ksh-i. Only a subset of built-in commands in ksh-i treat 34*35113Smarc parameter assignments globally. In sh, all built-in commands and 35*35113Smarc functions treat parameter assignments as globals. (Notice that 5.0 36*35113Smarc and 5.2 treat parameter assignments to pwd and echo in an 37*35113Smarc incompatible way). 38*35113Smarc 39*35113Smarc6. The output of some built-in commands and error messages is different 40*35113Smarc in a few cases, for example times produces two lines of output in ksh-i. 41*35113Smarc 42*35113Smarc7. While loops with redirection are not executed in a separate process 43*35113Smarc in ksh-i so assignments made within loops remain in effect after the 44*35113Smarc loop completes. 45*35113Smarc 46*35113Smarc8. The semantics of functions are somewhat different. Ksh-i can have 47*35113Smarc local variables and allow recursive functions. Errors in functions 48*35113Smarc abort the function but not the script that they are in. 49*35113Smarc 50*35113Smarc9. The name space for functions and variables is separate in ksh-i. In 51*35113Smarc /bin/sh they share the same space. The unset builtin requires 52*35113Smarc a -f flag to unset a function in ksh-i. 53*35113Smarc 54*35113Smarc10. Words that begin with ~ may be expanded in ksh-i. Sh does not have 55*35113Smarc this feature. 56*35113Smarc 57*35113Smarc11. The character ^ is not special in ksh-i. In sh it is an archaic 58*35113Smarc synonym for |. 59*35113Smarc 60*35113Smarc12. Whenever (( occurs where a command name is valid, ksh-i assumes 61*35113Smarc that an arithmetic expression follows. In sh this means a 62*35113Smarc sub-shell inside a sub-shell. 63*35113Smarc 64*35113Smarc13. Non-blank contiguous IFS delimiters generate a null input argument. 65*35113Smarc Therefore, you can use IFS=: and correctly read the /etc/profile 66*35113Smarc file even when fields are omitted. In sh, multiple delimiters 67*35113Smarc count as a single delimiter. 68*35113Smarc 69*35113Smarc14. Arithmetic test comparison operators (-eq, -lt, ...) allow any 70*35113Smarc arithmetic expressions. Sh allows only constants. If you say 71*35113Smarc test x -eq 0 in sh, which is meaningless, it returns true, but 72*35113Smarc in ksh-i it depends on the value of the variable x. If there 73*35113Smarc is no variable x, then ksh-i produces an error message. 74*35113Smarc 75*35113Smarc15. The environment handed down to a program is not sorted in ksh-i. 76*35113Smarc A user should not reply in this quirk of sh since any user 77*35113Smarc program can provide an environment list which does not have 78*35113Smarc to be sorted. (Getenv(3) does not assume a sorted list). 79*35113Smarc 80*35113Smarc16. There is an alias hash in ksh-i which does what the 5.2 has 81*35113Smarc built-in hash does except for the -r flag. In ksh-i, you must say 82*35113Smarc PATH=$PATH to achieve the same result. 83*35113Smarc 84*35113Smarc17. The expansion of "$@" with no arguments produces the null string 85*35113Smarc in the Bourne shell and produces nothing with ksh-i when there are 86*35113Smarc no arguments. I am not sure whether this is a bug in the Bourne 87*35113Smarc shell or intentional. The manual page leads me to think that it 88*35113Smarc is a bug. Set -- with no arguments unsets the positional parameter 89*35113Smarc list in ksh-i. Thus, scripts that use set -- "$@" when there are 90*35113Smarc so positional parameters will not break. 91*35113Smarc 92*35113Smarc18. Ksh-i accepts options of the form -x -v as well as -xv both for 93*35113Smarc invocation and for the set builtin. The Bourne shell only allows 94*35113Smarc one option parameter. 95*35113Smarc 96*35113Smarc19. Ksh-i does not allow unbalanced quotes with any script. If the end of 97*35113Smarc file is reached before a balancing quote in sh, it quietly inserts 98*35113Smarc the balancing quote. Ksh-i, behaves like sh for eval statements. 99*35113Smarc 100*35113Smarc20. Failures of any built-in command cause a script to abort in sh. Ksh-i 101*35113Smarc scripts will only abort on errors in certainly documented built-ins. 102*35113Smarc In this respect ksh-i treats most built-in commands semantically the 103*35113Smarc same as non-builtin commands. 104*35113Smarc 105*35113Smarc21. The sequence $( is special in ksh-i. In sh the sequence is illegal 106*35113Smarc unless quoted. When used with "", $( must be preceded by a \ in 107*35113Smarc ksh-i to remove its special meaning. 108*35113Smarc 109*35113Smarc22. The built-in command exec when used without arguments (for I/O 110*35113Smarc redirection), will close on exec each file unit greater than 2. 111*35113Smarc 112*35113Smarc23. Ksh-i has some added security features which may cause some setuid 113*35113Smarc programs to stop working. Whenever the real and effective uid 114*35113Smarc of a shell program is different, ksh-i sets the -p mode which resets 115*35113Smarc the PATH and omits user profiles. The file /etc/suid_profile is 116*35113Smarc executed instead of the ENV file. 117*35113Smarc 118*35113SmarcI am interested in expanding this list so please let me know if you 119*35113Smarcuncover any others. 120