「Bash」- 内建命令(学习笔记)

  CREATED BY JENKINSBOT

history
命令执行的历史记录操作、查看;

kill
用于向job或者进程发送信号。

trap [-lp] [[arg] sigspec …]

The command arg is to be read and executed when the shell receives

signal(s) sigspec. If arg is absent (and there is a single

sigspec) or -, each specified signal is reset to its original dis‐

position (the value it had upon entrance to the shell). If arg is

the null string the signal specified by each sigspec is ignored by

the shell and by the commands it invokes. If arg is not present

and -p has been supplied, then the trap commands associated with

each sigspec are displayed. If no arguments are supplied or if

only -p is given, trap prints the list of commands associated with

each signal. The -l option causes the shell to print a list of

signal names and their corresponding numbers. Each sigspec is

either a signal name defined in <signal.h>, or a signal number.

Signal names are case insensitive and the SIG prefix is optional.

If a sigspec is EXIT (0) the command arg is executed on exit from the shell.

如果sigspec为DEBUG,对于命令、case命令、select命令、命令的每个算术,会在每个简单的命令并且在shell函数中执行的第一个命令之前先执行命令arg(请参见SHELL GRAMMAR章节)。
有关shopt内置的extdebug选项对trapDEBUG的影响的详细信息,参阅shopt内置的extdebug选项的说明。

If a sigspec is DEBUG, the command arg is executed

before every simple command, for command, case command, select com‐

mand, every arithmetic for command, and before the first command

executes in a shell function (see SHELL GRAMMAR above).

If a sigspec is RETURN,

the command arg is executed each time a shell function or a script

executed with the . or source builtins finishes executing.

If a sigspec is ERR, the command arg is executed whenever a a pipe‐

line (which may consist of a single simple command), a list, or a

compound command returns a non-zero exit status, subject to the

following conditions. The ERR trap is not executed if the failed

command is part of the command list immediately following a while

or until keyword, part of the test in an if statement, part of a

command executed in a && or || list except the command following

the final && or ||, any command in a pipeline but the last, or if

the command’s return value is being inverted using !. These are

the same conditions obeyed by the errexit (-e) option.

Signals ignored upon entry to the shell cannot be trapped or reset.

Trapped signals that are not being ignored are reset to their orig‐

inal values in a subshell or subshell environment when one is cre‐

ated. The return status is false if any sigspec is invalid; other‐

wise trap returns true.

作业控制(Job Control)

bg [jobspec …]
恢复jobspec指定的Job,并在后台运行,如同它已经以在后台运行。
如果jobspec未指定,则使用当前的Job。
除非在禁用Job控制,否则运行bg jobspec返回0;或者在启用了Job控制的情况下,没有找到任何指定的jobspec或在没有Job控制下已经启动。

fg [jobspec]
恢复jobspec指定的Job,并在前台运行。
如果jobspec未指定,则使用当前的Job。
返回状态是放置在前台的命令;在禁用Job控制时,运行时返回为非零;在启用作业控制的情况下运行时,jobspec指定的Job不存在,或在没有Job控制下已经启动。

wait [-n] [n …]
等待每个指定的子进程,并返回其终止状态。n可以是ProcessIDJObID;如果给定了JObID,则等待该作业管道中的所有进程。
如果没有给出n,则等待所有当前活动的子进程,并且返回状态为0
如果给出了n,如果指定了不存在的Process或Job,则返回状态为127,否则返回状态是最后一个等待的ProcessJob的退出状态。
如果提供了-n选项,则等待任何Job终止并返回其退出状态。

参考文献

SHELL中的内建命令https://www.gnu.org/software/bash/manual/bash.html#Builtin-Index
Internal Commands and Builtins: http://www.tldp.org/LDP/abs/html/internal.html