Bash - Builtin Commands

1 - About

builtin refers to:

  • a builtin command. See list
  • or to the specific builtin command. See builtin (useful when defining a function whose name is the same as a shell builtin)

3 - builtin


builtin shell-builtin [arguments]

The builtin command execute the specified shell builtin, passing it arguments, and return its exit status.

This is useful when defining a function whose name is the same as a shell builtin, retaining the functionality of the builtin within the function.

The cd builtin is commonly redefined this way.

The return status is false if shell-builtin is not a shell builtin command.

4 - List

You can list enabled and disabled command with the builtin command with the enable command


enable -p

Example of output:


enable .
enable :
enable [
....

List:

5 - Syntax

Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts – to signify the end of the options.

For example, the :, true, false, and test builtins do not accept options.

shopt [-pqsu] [-o] [optname …] Toggle the values of variables controlling optional shell behav-ior. With no options, or with the -p option, a list of all set- table options is displayed, with an indication of whether or noteach is set. The -p option causes output to be displayed in a form that may be reused as input. Other options have the fol-lowing meanings: -s Enable (set) each optname.-u Disable (unset) each optname. -q Suppresses normal output (quiet mode); the return statusindicates whether the optname is set or unset. If multiple optname arguments are given with -q, the returnstatus is zero if all optnames are enabled; non-zero oth- erwise.-o Restricts the values of optname to be those defined for the -o option to the set builtin. If either -s or -u is used with no optname arguments, the dis- play is limited to those options which are set or unset, respec-tively. Unless otherwise noted, the shopt options are disabled (unset) by default. The return status when listing options is zero if all optnames are enabled, non-zero otherwise. When setting or unsettingoptions, the return status is zero unless an optname is not a valid shell option. The list of shopt options is: cdable_varsIf set, an argument to the cd builtin command that is not a directory is assumed to be the name of a variablewhose value is the directory to change to. cdspell If set, minor errors in the spelling of a directory com-ponent in a cd command will be corrected. The errors checked for are transposed characters, a missing charac-ter, and one character too many. If a correction is found, the corrected file name is printed, and the com-mand proceeds. This option is only used by interactive shells.checkhash If set, bash checks that a command found in the hash ta-ble exists before trying to execute it. If a hashed command no longer exists, a normal path search is per-formed. checkwinsizeIf set, bash checks the window size after each command and, if necessary, updates the values of LINES andCOLUMNS. cmdhist If set, bash attempts to save all lines of a multiple-line command in the same history entry. This allows easy re-editing of multi-line commands.dotglob If set, bash includes filenames beginning with a ‘.’ in the results of pathname expansion.execfail If set, a non-interactive shell will not exit if it can-not execute the file specified as an argument to the exec builtin command. An interactive shell does notexit if exec fails. expand_aliasesIf set, aliases are expanded as described above under ALIASES. This option is enabled by default for interac-tive shells. extdebugIf set, behavior intended for use by debuggers is enabled:1. The -F option to the declare builtin displays the source file name and line number corresponding toeach function name supplied as an argument. 2. If the command run by the DEBUG trap returns anon-zero value, the next command is skipped and not executed.3. If the command run by the DEBUG trap returns a value of 2, and the shell is executing in a sub-routine (a shell function or a shell script exe- cuted by the . or source builtins), a call toreturn is simulated. 4. BASH_ARGC and BASH_ARGV are updated as describedin their descriptions above. 5. Function tracing is enabled: command substitu-tion, shell functions, and subshells invoked with ( command ) inherit the DEBUG and RETURN traps.6. Error tracing is enabled: command substitution, shell functions, and subshells invoked with (command ) inherit the ERROR trap. extglob If set, the extended pattern matching features describedabove under Pathname Expansion are enabled. extquoteIf set, $'string' and $“string”quoting is performed within ${parameter} expansions enclosed in doublequotes. This option is enabled by default. failglobIf set, patterns which fail to match filenames during pathname expansion result in an expansion error.force_fignore If set, the suffixes specified by the FIGNORE shellvariable cause words to be ignored when performing word completion even if the ignored words are the only possi-ble completions. See SHELL VARIABLES above for a description of FIGNORE. This option is enabled bydefault. gnu_errfmtIf set, shell error messages are written in the standard GNU error message format.histappend If set, the history list is appended to the file namedby the value of the HISTFILE variable when the shell exits, rather than overwriting the file.histreedit If set, and readline is being used, a user is given theopportunity to re-edit a failed history substitution. histverifyIf set, and readline is being used, the results of his- tory substitution are not immediately passed to theshell parser. Instead, the resulting line is loaded into the readline editing buffer, allowing further modi-fication. hostcompleteIf set, and readline is being used, bash will attempt to perform hostname completion when a word containing a @is being completed (see Completing under READLINE above). This is enabled by default.huponexit If set, bash will send SIGHUP to all jobs when an inter-active login shell exits. interactive_commentsIf set, allow a word beginning with # to cause that word and all remaining characters on that line to be ignoredin an interactive shell (see COMMENTS above). This option is enabled by default.lithist If set, and the cmdhist option is enabled, multi-line commands are saved to the history with embedded newlinesrather than using semicolon separators where possible. login_shellThe shell sets this option if it is started as a login shell (see INVOCATION above). The value may not bechanged. mailwarnIf set, and a file that bash is checking for mail has been accessed since the last time it was checked, themessage ‘‘The mail in mailfile has been read’’ is dis- played.no_empty_cmd_completion If set, and readline is being used, bash will notattempt to search the PATH for possible completions when completion is attempted on an empty line.nocaseglob If set, bash matches filenames in a case-insensitivefashion when performing pathname expansion (see Pathname Expansion above).nocasematch If set, bash matches patterns in a case-insensitivefashion when performing matching while executing case or ] Suspend the execution of this shell until it receives a SIGCONTsignal. When the suspended shell is a background process, it can be restarted by the fg command. For more information, readthe JOB CONTROL section. The suspend command can not suspend the login shell. However, when -f option is specified, suspend com-mand can suspend even login shell. The return status is 0 unless the shell is a login shell and -f is not supplied, or ifjob control is not enabled. test expr[ expr ] Return a status of 0 or 1 depending on the evaluation of theconditional expression expr. Each operator and operand must be a separate argument. Expressions are composed of the primariesdescribed above under CONDITIONAL EXPRESSIONS. test does not accept any options, nor does it accept and ignore an argument of–as signifying the end of options. Expressions may be combined using the following operators,listed in decreasing order of precedence. ! expr True if expr is false.( expr ) Returns the value of expr. This may be used to overridethe normal precedence of operators. expr1 -a expr2True if both expr1 and expr2 are true. expr1 -o expr2True if either expr1 or expr2 is true. test and [ evaluate conditional expressions using a set of rulesbased on the number of arguments. 0 argumentsThe expression is false. 1 argumentThe expression is true if and only if the argument is not null.2 arguments If the first argument is !, the expression is true if andonly if the second argument is null. If the first argu- ment is one of the unary conditional operators listedabove under CONDITIONAL EXPRESSIONS, the expression is true if the unary test is true. If the first argument isnot a valid unary conditional operator, the expression is false.3 arguments If the second argument is one of the binary conditionaloperators listed above under CONDITIONAL EXPRESSIONS, the result of the expression is the result of the binary testusing the first and third arguments as operands. If the first argument is !, the value is the negation of thetwo-argument test using the second and third arguments. If the first argument is exactly ( and the third argumentis exactly ), the result is the one-argument test of the second argument. Otherwise, the expression is false.The -a and -o operators are considered binary operators in this case.4 arguments If the first argument is !, the result is the negation ofthe three-argument expression composed of the remaining arguments. Otherwise, the expression is parsed and eval-uated according to precedence using the rules listed above.5 or more arguments The expression is parsed and evaluated according toprecedence using the rules listed above. times Print the accumulated user and system times for the shell andfor processes run from the shell. The return status is 0. trap [-lp] ] sigspec …] The command arg is to be read and executed when the shellreceives signal(s) sigspec. If arg is absent (and there is a single sigspec) or -, each specified signal is reset to itsoriginal disposition (the value it had upon entrance to the shell). If arg is the null string the signal specified by eachsigspec is ignored by the shell and by the commands it invokes. If arg is not present and -p has been supplied, then the trapcommands associated with each sigspec are displayed. If no arguments are supplied or if only -p is given, trap prints thelist of commands associated with each signal. The -l option causes the shell to print a list of signal names and their cor-responding numbers. Each sigspec is either a signal name defined in <signal.h>, or a signal number. Signal names arecase insensitive and the SIG prefix is optional. If a sigspec is EXIT (0) the command arg is executed on exit from the shell.If a sigspec is DEBUG, the command arg is executed before every simple command, for command, case command, select command, everyarithmetic for command, and before the first command executes in a shell function (see SHELL GRAMMAR above). Refer to thedescription of the extdebug option to the shopt builtin for details of its effect on the DEBUG trap. If a sigspec is ERR,the command arg is executed whenever a simple command has a non-zero exit status, subject to the following conditions. TheERR 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 && or ││ list, or if the command’s return value is being inverted via !. Theseare the same conditions obeyed by the errexit option. If a sigspec is RETURN, the command arg is executed each time a shellfunction or a script executed with the . or source builtins fin- ishes executing. Signals ignored upon entry to the shell cannotbe trapped or reset. Trapped signals that are not being ignored are reset to their original values in a child process when it iscreated. The return status is false if any sigspec is invalid; otherwise trap returns true. type [-aftpP] name [name …] With no options, indicate how each name would be interpreted ifused as a command name. If the -t option is used, type prints a string which is one of alias, keyword, function, builtin, orfile if name is an alias, shell reserved word, function, builtin, or disk file, respectively. If the name is not found,then nothing is printed, and an exit status of false is returned. If the -p option is used, type either returns thename of the disk file that would be executed if name were speci- fied as a command name, or nothing if ‘‘type -t name’’ would notreturn file. The -P option forces a PATH search for each name, even if ‘‘type -t name’’ would not return file. If a command ishashed, -p and -P print the hashed value, not necessarily the file that appears first in PATH. If the -a option is used, typeprints all of the places that contain an executable named name. This includes aliases and functions, if and only if the -poption is not also used. The table of hashed commands is not consulted when using -a. The -f option suppresses shell func-tion lookup, as with the command builtin. type returns true if any of the arguments are found, false if none are found. ulimit [-SHacdefilmnpqrstuvx [limit Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.The -H and -S options specify that the hard or soft limit is set for the given resource. A hard limit cannot be increased onceit is set; a soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the softand hard limits are set. The value of limit can be a number in the unit specified for the resource or one of the special valueshard, soft, or unlimited, which stand for the current hard limit, the current soft limit, and no limit, respectively. Iflimit is omitted, the current value of the soft limit of the resource is printed, unless the -H option is given. When morethan one resource is specified, the limit name and unit are printed before the value. Other options are interpreted as fol-lows: -a All current limits are reported-c The maximum size of core files created -d The maximum size of a process’s data segment-e The maximum scheduling priority (“nice”) -f The maximum size of files written by the shell and itschildren -i The maximum number of pending signals-l The maximum size that may be locked into memory -m The maximum resident set size (has no effect on Linux)-n The maximum number of open file descriptors (most systems do not allow this value to be set)-p The pipe size in 512-byte blocks (this may not be set) -q The maximum number of bytes in POSIX message queues-r The maximum real-time scheduling priority -s The maximum stack size-t The maximum amount of cpu time in seconds -u The maximum number of processes available to a singleuser -v The maximum amount of virtual memory available to theshell -x The maximum number of file locks If limit is given, it is the new value of the specified resource (the -a option is display only). If no option is given, then -fis assumed. Values are in 1024-byte increments, except for -t, which is in seconds, -p, which is in units of 512-byte blocks,and -n and -u, which are unscaled values. The return status is 0 unless an invalid option or argument is supplied, or an erroroccurs while setting a new limit. umask [-p] [-S] [mode]The user file-creation mask is set to mode. If mode begins with a digit, it is interpreted as an octal number; otherwise it isinterpreted as a symbolic mode mask similar to that accepted by chmod(1). If mode is omitted, the current value of the mask isprinted. The -S option causes the mask to be printed in sym- bolic form; the default output is an octal number. If the -poption is supplied, and mode is omitted, the output is in a form that may be reused as input. The return status is 0 if the modewas successfully changed or if no mode argument was supplied, and false otherwise. unalias [-a] [name …] Remove each name from the list of defined aliases. If -a issupplied, all alias definitions are removed. The return value is true unless a supplied name is not a defined alias. unset [-fv] [name …] For each name, remove the corresponding variable or function.If no options are supplied, or the -v option is given, each name refers to a shell variable. Read-only variables may not beunset. If -f is specified, each name refers to a shell func- tion, and the function definition is removed. Each unset vari-able or function is removed from the environment passed to sub- sequent commands. If any of RANDOM, SECONDS, LINENO, HISTCMD,FUNCNAME, GROUPS, or DIRSTACK are unset, they lose their special properties, even if they are subsequently reset. The exit sta-tus is true unless a name is readonly. wait [n …]Wait for each specified process and return its termination sta- tus. Each n may be a process ID or a job specification; if ajob spec is given, all processes in that job’s pipeline are waited for. If n is not given, all currently active child pro-cesses are waited for, and the return status is zero. If n specifies a non-existent process or job, the return status is127. Otherwise, the return status is the exit status of the last process or job waited for.

6 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap