Tag Archives: ksh

Shells: ksh Tab Completion

If you are using the public domain version of the Korn Shell (pdksh), you can add the following line to your .kshrc and (providing ENV is set), you will have tab completion in vi mode:

You can see which shell options are currently set by running:

Please note, vi-tabcomplete is an option within the public domain Korn Shell only, and will not work with the “standard” ksh provided by many OS’s. In this case, you’ll have to make do with Esc-\ for filename completion.

Shells: How to Respond to a Single Keystroke Within a Script

If you are using a newer Bourne-compatible shell such as (pd)ksh or bash, and have a modern terminal, you can take advantage of the -icanon stty mode to good effect. This mode allows your scripts to respond to a single keystroke rather than requiring the user to hit “return” after entering a character. This is useful for the familiar “Press any key to continue … ” type messages, but can also be used to provide control of programs.

Ensure that you restore your old stty settings before exiting. This is probably best achieved by using traps. The following script demostrates these concepts well, and gives the foundations of a Minesweeper-style grid, cursors, and cell-marking.

Launching Simultaneous Processes and Monitoring Exit Statuses

Let’s say you have three scripts. You want to execute them simultaneously (or as close to simultaneous as is practicable). You then want to examine all of their exit statuses, and maybe perform some actions accordingly.

The easiest way is using a script such as the following, capturing the PID of each process as it is launched, and then using wait to wait for the specified process to return its termination status. For example: