您正在查看: Shell 分类下的文章

Shell Built-In Commands

9.13 shell Built-In Commands


9.13 shell Built-In Commands


The shell has a number of commands that are built-in to 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 give you online help for any built-in command. The built-in commands are listed in Table 9.12 on page 481.


Table 9.12. Built-In Commands

Command

What It Does

:

Do-nothing command; returns exit status zero.

. file

The dot command reads and executes command from file.

break [n]

See the looping commands on page 443.

:

Do-nothing command; returns 0 exit status.

.

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

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.

break

Breaks out of the innermost loop.

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.

cd [arg]

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

command command* [arg]

Runs a command even if a function has the same name; i.e., bypasses function lookup.

continue [n]

See the looping commands on page 444.

declare [var]

Displays all variables or declares variables with optional attributes.

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.

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.

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.

getopts

Used in shell scripts to parse command line and check for legal options.

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 9.2 on page 396.

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

Diplays and sets process resource limits.

umask [ octal digits ]

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

unalias

Unsets aliases.

unset [ name ]

Unset value of variable or function.

wait [ pid#n ]

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

Bash Options

9.12 Bash Options


9.12 Bash Options


9.12.1 shell Invocation Options

When the shell is started using the bash command, it can take options to modify its behavior. There are two types of options: single-character options and multicharacter options. The single-character options consist of a single leading dash followed by a single character. The multicharacter options consist of two leading dashes and any number of characters. Multicharacter options must appear before single-character options. An interactive login shell normally starts u