Previous Section  < Day Day Up >  Next Section

14.12. Shell Built-In Commands

The shell has a number of commands that are built into its source code. Because the commands are built-in, the shell doesn't have to locate them on disk, making execution much faster. The help feature provided with bash gives you online help for any built-in command. The built-in commands are listed in Table 14.12.

Table 14.12. Built-In Commands

Command

What It Does

.

Executes program in context of current process; same as source.

. file

The dot command reads and executes command from file.

:

Do-nothing command; returns 0 exit status.

alias

Lists and creates "nicknames" for existing commands.

bg

Puts a job in the background.

bind

Displays current key and function bindings, or binds keys to a readline function or macro.[a]

break

Breaks out of the innermost loop.

break [n]

See "The break Command" on page 919.

builtin [sh–builtin [args]]

Runs a shell built-in, passing it args, and returning 0 exit status. Useful if a function and built-in have the same name.[a]

cd [arg]

Changes the directory to home if no arg or to value of arg.

command command [arg]

Runs a command even if a function has the same name (i.e., bypasses function lookup).[a]

continue [n]

See "The continue Command" on page 920.

declare [var]

Displays all variables or declares variables with optional attributes.[a]

dirs

Displays a list of currently remembered directories resulting from pushd.

disown

Removes an active job from the job table.

echo [args]

Displays args terminated with a newline.

enable

Enables and disables shell built-in commands.[a]

eval [args]

Reads args as input to the shell and executes the resulting command(s).

exec command

Runs command in place of this shell.

exit [n]

Exits the shell with status n.

export [var]

Makes var known to subshells.

fc

History's fix command for editing history commands.

fg

Puts background job into foreground.

getopts

Parses and processes command-line options.

hash

Controls the internal hash table for quicker searches for commands.

help [command]

Displays helpful info about built-in commands and, if command is specified, detailed help about that built-in command.[a]

history

Displays the history list with line numbers.

jobs

Lists jobs put in the background.

kill [–signal process]

Sends the signal to the PID number or job number of the process. Type kill –l for a list of signals.

let

Used for evaluating arithmetic expressions and assigning results of arithmetic calculations to variables.

local

Used in functions to restrict the scope of variables to the function.

logout

Exits the login shell.

popd

Removes entries from the directory stack.

pushd

Adds entries to the directory stack.

pwd

Prints present working directory.

read [var]

Reads line from standard input into variable var.

readonly [var]

Makes variable var read-only. Cannot be reset.

return [n]

Returns from a function where n is the exit value given to the return.

set

Sets options and positional parameters. See Table 14.2 on page 875.

shift [n]

Shifts positional parameters to the left n times.

stop pid

Halts execution of the process number PID.

suspend

Stops execution of the current shell (but not if a login shell).

test

Checks file types and evaluates conditional expressions.

times

Prints accumulated user and system times for processes run from this shell.

trap [arg] [n]

When shell receives signal n (0, 1, 2, or 15), executes arg.

type [command]

Prints the type of command (e.g., pwd is a built-in shell command).

typeset

Same as declare. Sets variables and gives them attributes.

ulimit

Displays and sets process resource limits.

umask [octal digits]

Sets user file creation mode mask for owner, group, and others.

unalias

Unsets aliases.

unset [name]

Unsets value of variable or function.

wait [pid#n]

Waits for background process with PID number n and reports termination status.


[a] Option applies to bash 2.x and later.

    Previous Section  < Day Day Up >  Next Section