Use Qedit/UX for Re-executing Shell Commands

The POSIX and Korn shells both have a command history feature. By default, the file .sh_history in the user's home directory ($home) contains the last 128 commands used. You can override the default history filename by setting the HISTFILE environment variable (e.g., export HISTFILE="MyHistory"). You can also change the number of commands in the history file by setting the HISTSIZE variable (e.g., export HISTSIZE=250). The command history file can be shared by multiple users, so you can access someone else's commands. You can even see the commands you used yesterday because the content of the file is saved between sessions.

You can use the built in fc command list to edit and execute one or more commands from the history file. The general syntax is:

      fc [-e editor] [-nlr] [first [last]]
      fc -e - [in-line edit]  [command reference]
fc Without any arguments, this command returns the most recent command in the history file, which you can edit, and executes the modified command when you exit the editor.
-l Lists the command(s) specified in command reference. If there is no command reference argument, it lists the last 16 commands.
-e Combined with the in-line edit argument, this argument allows you to perform a simple string replacement in the specified command.
- This option indicates that no interactive editing is required and that the command will be executed immediately. It can be used in conjunction with -e to change a string before execution.
[command reference] can be a single command line number (e.g., fc 100). Used with -l, fc lists all the commands starting from the specified number to the most recent command. Used with other options, fc performs the specified operation on that one line. This option can also use the start and end numbers in the command history (e.g., fc 100 105), in which case the operation will be performed on all lines between the specified numbers. This option can also use a string of one or more characters (e.g., fc c) to return the most recent command that starts with the specified string.
[in-line edit] performs a simple string replacement when combined with the -e option. The syntax is old=new. The fc command replaces the first occurrence of old with new.

To edit commands, fc invokes the editor specified in the FCEDIT variable. If this variable is not set, /bin/ed is used. To use Qedit/UX instead, enter

        export FCEDIT='qedit "-c m@;k,yes;e" '

During an edit operation, the requested lines are put in a temporary file. This file is then passed to Qedit. After editing the lines, you should save your changes before exiting Qedit, at which time the shell will execute the modified commands.

Because the fc command is fairly simple, you can use it by itself. If you want to assign specific names to each option, you can use aliases. Those familiar with MPE will recognize the following:

   alias listredo="fc -l"
   alias redo="fc"
   alias xeq="fc -e -"     {"do" cannot be used because it is already a valid shell command}

From that point, you can use:

   listredo             {to list the last 16 commands entered}
   redo 100          {to modify and execute command line number 100}
   xeq cd              {to execute the most recent command starting with cd}

Qedit/UX displays its banner every time you edit a command. Unfortunately, there is no way to avoid this. You can further customize your Qedit/UX environment by inserting Set commands in the FCEDIT variable, creating a local .qeditmgr file or system-wide /usr/robelle/qeditmgr file. You could then choose one of the three Qedit/UX Modify modes (Robelle, HP or QZModify), or you can get into full-screen mode directly.
[Francois Desrochers]

....Back to the Qedit Q&A Page