Thursday, September 30, 2021

Solaris 11.4 - Differences Between ksh88 and ksh93


Solaris 11.4 - Differences between ksh88 and ksh93

Abstract:

People who have used UNIX systems for a long period of time, there is sometimes a question of shell compatibility, especially when software is being ported to newer platforms. Differences are noted in Solaris 11.4

Finding Differences

sun9999/root# ssh sun2581
Last login: Wed Sep 29 22:03:38 2021 from 192.168.234.5
Oracle Solaris 11.4.37.101.1                    Assembled August 2021

sun9999/root# uname -a
SunOS sun9999 5.11 11.4.37.101.1 sun4v sparc sun4v logical-domain


sun9999/root# cat /usr/share/doc/ksh/COMPATIBILITY

                KSH-93 VS. KSH-88


The following is a list of known incompatibilities between ksh-93 and ksh-88.
I have not include cases that are clearly bugs in ksh-88.  I also have
omitted features that are completely upward compatible.

1.      Functions, defined with name() with ksh-93 are compatible with
        the POSIX standard, not with ksh-88.  No local variables are
        permitted, and there is no separate scope.  Functions defined
        with the function name syntax, maintain compatibility.
        This also affects function traces.

2.      ! is now a reserved word.  As a result, any command by that
        name will no longer work with ksh-93.

3.      The -x attribute of alias and typeset -f is no longer
        effective and the ENV file is only read for interactive
        shells.  You need to use FPATH to make function definitions
        visible to scripts.

4.      A built-in command named command has been added which is
        always found before the PATH search.  Any script which uses
        this name as the name of a command (or function) will not
        be compatible.

5.      The output format for some built-ins has changed.  In particular
        the output format for set, typeset and alias now have single
        quotes around values that have special characters.  The output
        for trap without arguments has a format that can be used as input.

6.      With ksh-88, a dollar sign ($') followed by a single quote was
        interpreted literally.  Now it is an ANSI-C string.  You
        must quote the dollar sign to get the previous behavior.
        Also, a $ in front of a " indicates that the string needs
        to be translated for locales other than C or POSIX.  The $
        is ignored in the C and POSIX locale.

7.      With ksh-88, tilde expansion did not take place inside ${...}.
        with ksh-93, ${foo-~} will cause tilde expansion if foo is
        not set.  You need to escape the ~ for the previous behavior.

8.      Some changes in the tokenizing rules where made that might
        cause some scripts with previously ambiguous use of quoting
        to produce syntax errors.

9.      Programs that rely on specific exit values for the shell,
        (rather than 0 or non-zero) may not be compatible.  The
        exit status for many shell failures has been changed.

10.     Built-ins in ksh-88 were always executed before looking for
        the command in the PATH variable.  This is no longer true.
        Thus, with ksh-93, if you have the current directory first
        in your PATH, and you have a program named test in your
        directory, it will be executed when you type test; the
        built-in version will be run at the point /bin is found
        in your PATH.

11.     Some undocumented combinations of argument passing to ksh
        builtins no longer works since ksh-93 is getopts conforming
        with respect to its built-ins.  For example, typeset -8i
        previously would work as a synonym for typeset -i8.

12.     Command substitution and arithmetic expansion are now performed
        on PS1, PS3, and ENV when they are expanded.  Thus,  ` and $(
        as part of the value of these variables must be preceded by a \
        to preserve their previous behavior.

13.     The ERRNO variable has been dropped.

14.     If the file name following a redirection symbol contain pattern
        characters they will only be expanded for interactive shells.

15.     The arguments to a dot script will be restored when it completes.

16.     The list of tracked aliases is not displayed with alias unless
        the -t option is specified.

17.     The POSIX standard requires that test "$arg" have exit status
        of 0, if and only if $arg is null.  However, since this breaks
        programs that use test -t, ksh-93 treats an explicit test -t
        as if the user had entered test -t 1.

18.     The ^T directive of emacs mode has been changed to work the
        way it does in gnu-emacs.

19.     ksh-88 allowed unbalanced parenthes within ${name op val} whereas
        ksh-93 does not.  Thus, ${foo-(} needs to be written as ${foo-\(}
        which works with both versions.

20.     kill -l in ksh-93 lists only the signal names, not their numerical
        values.

21.     Local variables defined by typeset are statically scoped in
        ksh-93.  In ksh-88 they were dynamically scoped although this
        behavior was never documented.

22.     The value of the variable given to getopts is set to ? when
        the end-of-options is reached to conform to the POSIX standard.

23.     Since the POSIX standard requires that octal constants be
        recongnized, doing arithmetic on typeset -Z variables can
        yield different results that with ksh-88.  Most of these
        differences were eliminated in ksh-93o.  Starting in ksh-93u+, the
        let command no longer recognizes octal constants starting with 0
        for compatibility with ksh-88 unless the option letoctal is on.

24.     Starting after ksh-93l, If you run ksh name, where name does
        not contain a /, the current directory will be searched
        before doing a path search on name as required by the POSIX
        shell standard.

25.     In ksh-93, cd - will output the directory that it changes
        to on standard output as required by X/Open.  With ksh-88,
        this only happened for interactive shells.

26.     As an undocumented feature of ksh-88, a leading 0 to an
        assignment of an integer variable caused that variable
        to be treated as unsigned.  This behavior was removed
        starting in ksh-93p.

27.     The getopts builtin in ksh-93 requires that optstring contain
        a leading + to allow options to begin with a +.

28.     In emacs/gmacs mode, control-v will not display the version when
        the stty lnext character is set to control-v or is unset.
        The sequence escape control-v will display the shell version.

29.     In ksh-88, DEBUG traps were executed. after each command.  In ksh-93
        DEBUG traps are exeucted before each command.

30.     In ksh-88, a redirection to a file name given by an empty string was
        ignored.  In ksh-93, this is an error.