ksh displays multibyte characters incorrectly when 'KEYBD trap' is enabled in profile file.

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • ksh (when used as the login shell for a user)
  • Multibyte locales including ja_JP.UTF-8

Issue

  • When 'KEYBD trap' is enabled, which it is by default when ksh is used as a login shell, ksh cannot display multibyte characters correctly.

If you type 'あいうえお' (Glyphs valid in ja_JP.UTF-8) in a terminal, it will instead display 'BDFHJ'.

```
$ BDFHJ
```

This issue has been verified in the ja_JP.UTF-8 locale but most likely impacts all multibyte locales (including locales based on the SJIS, various EUC, and UTF-8 character sets). Locales where the most commonly used characters are single byte characters (e.g. en_US.UTF-8) will see little to no impact as the usage of multibyte UTF-8 characters would be rare.

Resolution

  • To temporarily workaround this issue there are three things you can do.
    • The first is adding the following to any affected users ~/.kshrc:

      ```
      trap - KEYBD
      ```
      

This will remove the trap defined for KEYBD.

  • The second is to use bash as the login shell instead of ksh for the user and in the users .bashrc add exec /usr/bin/ksh at the end.

  • A third alternative is to modify /etc/kshrc and comment out the following:

      ```
      keybd_trap () {
        case ${.sh.edchar} in
          $'\e[1~') .sh.edchar=$'\001';; # Home = beginning-of-line
          $'\e[F')  .sh.edchar=$'\005';; # End = end-of-line
          $'\e[5~') .sh.edchar=$'\e>';; # PgUp = history-previous
          $'\e[6~') .sh.edchar=$'\e<';; # PgDn = history-next
          $'\e[3~') .sh.edchar=$'\004';; # Delete = delete-char
        esac
      }
      trap keybd_trap KEYBD
      ```
    

To disable those lines, you need to insert # at the beginning of lines.

    ```
    #keybd_trap () {
    #  case ${.sh.edchar} in
    #    $'\e[1~') .sh.edchar=$'\001';; # Home = beginning-of-line
    #    $'\e[F')  .sh.edchar=$'\005';; # End = end-of-line
    #    $'\e[5~') .sh.edchar=$'\e>';; # PgUp = history-previous
    #    $'\e[6~') .sh.edchar=$'\e<';; # PgDn = history-next
    #    $'\e[3~') .sh.edchar=$'\004';; # Delete = delete-char
    #  esac
    #}
    #trap keybd_trap KEYBD
    ```

To fully resolve the issue if you have used the first method simply running exec ksh from the login shell will prevent the issue from happening.
For any of the above method logging out and logging back in again will prevent the issue from happening.

NOTE: Updating /etc/kshrc will cause the file never to be replaced when you update the ksh rpm.

Since /etc/kshrc is a config file:

```
$ rpm -Vv ksh-20120801-139.el7.x86_64
.........  g /bin/ksh
.........    /bin/ksh93
.........    /bin/rksh
.........  c /etc/binfmt.d/kshcomp.conf
.........  c /etc/kshrc
.........  c /etc/skel/.kshrc
.........    /usr/bin/shcomp
.........    /usr/share/doc/ksh-20120801
.........  d /usr/share/doc/ksh-20120801/COMPATIBILITY
.........  d /usr/share/doc/ksh-20120801/RELEASE
.........  d /usr/share/doc/ksh-20120801/TYPES
.........  d /usr/share/man/man1/ksh.1.gz
.........  d /usr/share/man/man1/ksh93.1.gz
```

And the ksh.spec file in the srpm lists it as noreplace:

```
%config(noreplace) %{_sysconfdir}/kshrc
```

If you want to restore the config file to the package default after updating, you must copy /etc/kshrc.rpmnew over /etc/kshrc.
This procedure replaces the config file and disappear all modifications to the old file.
The first method stops this from happening but undoing it would still require a change to remove the unset.

  • This issue was being tracked at This content is not included.RHBZ#1503922. Red Hat will not address this issue in RHEL7 and RHEL8. And it has been documented as a know issue in the RHEL7 and RHEL8 release notes.
SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.