Shell Command History

Qedit 5.7 for HP-UX

Home Previous Next


Shell Command History

If you use the POSIX or Korn shell, you have access to a shell command history function. By default, the shell saves the last 128 commands you have entered. The default name is .sh_history and is located in your home directory. If you want to use a different file name, change the HISTFILE environment variable. If you want to change the number of commands saved, change the value of the HISTSIZE variable.

Normally, you recall commands from the history stack by using the fc command. This command calls up the default shell editor that works like the vi editor. You can instruct the shell to use Qedit/UX as your command line editor instead.

The first step, which is probably the most important one, is setting the FCEDIT variable. This variable specifies which editor you want to use to modify the commands. The default editor is /bin/ed. To change the editor, use

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

The export command is not mandatory, but it is good practice to include this command in case you start up another shell process. Also note that the quotes are very important. You begin with single quotes and enclose the Qedit/UX commands in double quotes.

In the next step, you can use the fc command to recall commands. It has a fairly simple set of arguments. You can also create your own set of commands using aliases.

A typical set of commands would include:

alias listredo="fc -l"
alias redo=fc
alias xeq="fc -e -"

NOTE: You cannot use "do" because it is a shell-reserved keyword. The xeq command is used instead.

The listredo command simply lists the most recent commands in the history stack. Its default (no argument) setting lists the last 16 commands.

When you use one line number as the argument, listredo lists all the commands from the specified line on. When you enter a few characters as the argument, the list starts with the last command that has these characters.

listredo 100 {list all commands starting with number 100}

listredo c@ {list all commands starting with a "c"}

With two line numbers, listredo lists all commands between these two lines.

listredo 100 105 {list commands 100 to 105}

The redo command recalls one or more commands and allows you to modify them before executing them. It uses similar syntax to listredo. If you do not specify an argument, redo recalls the last command you have entered. If you specify a command number, it recalls that particular entry. If you enter a string, it recalls the most recent command starting with that string. If you enter 2 numbers, it recalls all the commands between these 2 numbers and allows you to modify them, one by one.

The xeq command recalls one or more commands and executes them immediately. It works the same as the redo command. The only difference is that you are not able to modify the commands.


Home Previous Next