Builtin Shell Commands

bindkey [-l] function string

Bindkey is used to customize the shell's command-line editor. Any key on the keyboard can be mapped to any of a number of functions. The various functions are as follows:

Table 1. bindkey Functions

FunctionMeaning
backward-char move cursor left
backward-delete-char delete character to the left
backward-word move cursor left one word
beginning-of-line move cursor to beginning of line
clear-screen clear screen and redraw prompt
complete-word perform filename completion
delete-char delete character under cursor
down-history replace command line with next history
end-of-line move cursor to end of line
forward-char move cursor to the right
forward-word mvoe cursor one word to the right
kill-end-of-line delete line from the cursor to end of line
kill-whole-line delete the entire command line
list-choices list file completion matches
newline finished editing, accept command line
raw-char character as-is
redisplay redisplay the command line
toggle-cursor toggle between insert and overwrite cursor
undefined-char this key does nothing
up-history replace command line with previous history

Keys are bound to functions, not vice-versa. This means that you can have any number of commands refer to the same function. For example, the default bindings have CTRL-A and OA-< both bound to beginning-of-line.

Most of the function names are self-explanatory, and are explained in Chapter 2, but a few deserve discussion. raw-char is what you should bind a key that should be inserted into the command-line as-is. The regular printable ASCII set, such as the letters a-z, numbers, etc. are bound to raw-char. Control characters should not be bound to raw-char because the command-line editor will become confused (most control characters act as special GNO/ME console feature codes - see the GNO Kernel Reference Manual).

Any keystroke that should be rejected by the editor should be bound to undefined-char. By default, this includes control characters and OA-sequences that are not assigned to any editing features. Any key bound to undefined-char will cause gsh to beep and ignore the key.

You can actually bind key sequences, not just keystrokes, to functions. There is no limit other than memory to how many characters are in a command sequence.

Because terminals do not have the OA (Open Apple) key, OA is actually mapped by the kernel to a two-character sequence consisting of ESC and the key. For example, OA-Y would actually produce ESC-Y.

Control characters in the string are represented in ^X format; e.g. CTRL-A is represented by ^A. ESC (and OA) is represented by ^[.


gno%  bindkey kill-end-of-line ^K
    map Ctrl-K to kill-end-of-line (like Emacs)
gno%  bindkey clear-screen ^[^X
    map OA-Clear to clear-screen

commands

Displays a list of all built-in shell commands.

cd [pathname], chdir [pathname]

Changes the current working directory to pathname. If pathname is not given, the default home directory (i.e. the value of the HOME environment variable) is used. This makes it easy to move back to your home directory. Under gsh, unlike most UNIX shells, the cd is not necessary, except to change automatically to your HOME directory. If the first word on the command line is neither a builtin nor an external command, but is instead the name of a directory, a cd is implied and performed on the directory unless the NODIREXEC variable has been set.

clear

This command takes no arguments. When invoked, the screen will be cleared.

dirs

See pushd.

echo [-n] [arg ...]

Expands the "arg" expression(s) and outputs them to the screen. If the -n flag is specified, a newline character is not output after the last arg expression. Special escape sequences may also be included in the arguments, similar to those used in C strings:

\bbackspace
\fform feed (clears screen)
\nnewline
\rcarridge return
\ttab
\nnna decimal ASCII code

exit

Exits the shell or terminates a shell script.

history

This command displays the list of previous command-line entries. The number of entries saved is set in the HISTORY variable.

pushd [newdir | +n], popd [+n], dirs

These three commands maintain the shell's directory stack. Let's say you're working in a directory /src/myprogs/class/program.1/, and you want to temporarily go to another directory. Instead of having to cd there and cd back to a very long directory name (i.e., lots of typing), you can use the pushd command, like so:


gno%  pwd
/src/myprogs/class/program.1
gno%  pushd /etc
gno%  pwd
/etc
gno%  popd
gno%  pwd
/src/myprogs/class/program.1

The pushd command stores the current directory on a stack, and then changes the current directory to the argument newdir. When you want to go back to the original directory, type popd. The shell will pull the last directory off the stack and make that directory the current directory. If no argument is given, then the current directory is swapped with the directory that is currently on the top of the directory stack. If a digit argument, +n, is given, then the current directory will be swapped with the directory in the nth position on the directory stack.

The popd command, when given without an argument, will pop the directory that is on top of the directory stack, and make that directory the current directory. When given an argument of +n, popd will remove the nth directory from the stack. It does not change to that directory.

The dirs command displays the current directory stack.

pwd

Displays the current working directory. This is useful if you have not configured the PROMPT string to print your current working directory.

source

When a script is executed, gsh creates a new process to run the script. As a result, scripts cannot change the parent shell's environment. Instead of executing the script directly, you may use the source command which does not create a new process to execute the script. Thus, the source command is effectively exactly like typing all the commands in the script from the keyboard.

tset

The tset command causes the shell to reread the /etc/termcap file and reset its output system to use the terminal type specified in the TERM environment variable. On startup, after reading the gshrc file, gsh automatically does a tset. gsh also automatically does a tset whenever the TERM variable is changed with the set command. You would use tset manually if, for example, a utility changed the value of TERM.

which command [...]

Let's say that you are working on a new version of the venerable shell utility ls. Since a search of the hash table is done before searching the current directory, you might accidentally be using the wrong version of the command. You make changes and run the new program, but your changes don't seem to appear! Use the which command to check your sanity. Which also comes in handy in locating duplicate program names in the PATH directories (for example, an ls in both /bin and /usr/bin.)

The way to access a utility in the current directory which has the same name as a program in the PATH is to prefix the command name with '.', as in './ls'. See also rehash and unhash.