|
Size: 5275
Comment:
|
Size: 4378
Comment: Pruning dead links
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 2: | Line 2: |
The set of portable commands. |
|
| Line 9: | Line 11: |
| == . == | == Commands == |
| Line 11: | Line 13: |
| Alias for `source`. ---- |
||'''Command''' ||'''Description'''||'''Example'''|| ||`.` ||Alias for `source`|| || ||`:` ||No-op || || ||`alias` ||Creates an [[Bash/Alias|alias]]|| || ||`bind` || || || ||`builtin` ||Executes a builtin command|| || ||`caller` || || || ||`cd` ||Changes the current working directory|| || ||`command` ||Executes a command|| || ||`declare` ||Set a variable, optionally with a value|| || ||`dirs` || || || ||`disown` || || || ||`echo` || || || ||`enable` || || || ||`eval` ||Executes a command|| || ||`exec` ||Replaces the shell with a command|| || ||`exit` ||Causes a script or shell to exit immediately|| || ||`export` ||Marks one or more names as variables to be included in the environment of subsequently-called commands||`export varname="some value"`|| ||`fc` || || || ||`getopts` || || || ||`hash` || || || ||`help` ||Prints helpful information about a builtin command|| || ||`history` || || || ||`kill` || || || ||`let` || || || ||`local` ||Only valid within a function definition; see [[Bash/Function#Local_Scope|here]]|| || ||`logout` ||Exits a login shell immediately|| || ||`mapfile` || || || ||`popd` || || || ||`printf` || || || ||`pushd` || || || ||`pwd` ||Prints the current working directory|| || ||`read` || || || ||`readarray` || || || ||`readonly` || || || ||`set` ||Sets a [[Bash/ShellOptions|shell option]]|| || ||`shift` ||Renames the [[Bash/Variables#Positional_Variables|positional variables]]|| || ||`shopt` ||Sets a [[Bash/ShellOptions|shell option]]|| || ||`source` || || || ||`test` ||Executes a [[Bash/Test|test]]|| || ||`time` || || || ||`trap` ||Creates a trap || || ||`typeset` || || || ||`unalias` ||Removes an [[Bash/Alias|alias]]|| || ||`unset` ||Unsets a [[Bash/ShellOptions|shell option]]|| || ||`wait` || || || |
| Line 17: | Line 62: |
| == : == | === Builtin === |
| Line 19: | Line 64: |
| Does nothing; arguments passed to it are expanded but immediately discarded. ---- |
`builtin` can be useful to call a builtin command when there is a custom command with the same name. |
| Line 25: | Line 68: |
| == Alias == | === Cd === |
| Line 27: | Line 70: |
| See [[Bash/Alias|here]]. | Calling `cd` without an argument is the same as `cd ~`. |
| Line 29: | Line 72: |
| ---- | `cd -` changes the current working directory to the previous working directory. |
| Line 33: | Line 76: |
| == Bg == | === Command === |
| Line 35: | Line 78: |
| See [[Bash/JobControl|here]]. | `command` can be useful to call a command when there is a function with the same name. |
| Line 37: | Line 80: |
| ---- == Bind == ---- == Break == See [[Bash/Looping|here]]. ---- == Builtin == Execute a builtin command. This is only useful when reimplementing a builtin but still need to call the original builtin within the function. ---- == Caller == ---- == Cd == Change the current working directory to a new path. Can be a relative or absolute path, as well as the special `.` and `..` directories. Note the rules for [[Bash/Expansion#Tilde_Expansion|tilde expansion]] when using the `~` symbol here. `cd -` changes the current working directory to the previous working directory. There is also special behavior around specifying ''nothing''. `cd` is the same as `cd ~`. ---- == Command == Execute a command. This can be useful to call a command when there is a function with the same name. It can also be used to determine if a command is locally available. |
`command` is also commonly used to determine if a command is locally available. |
| Line 94: | Line 89: |
| ---- | |
| Line 97: | Line 91: |
== CompGen == See [[Bash/Completion|here]]. ---- == Complete == See [[Bash/Completion|here]]. ---- == CompOpt == See [[Bash/Completion|here]]. ---- == Continue == See [[Bash/Looping|here]]. ---- == Coproc == See [[Bash/JobControl|here]]. ---- == Declare == Set a variable, optionally with a value. {{{ declare a=1 b=2 c=3 }}} |
=== Declare === |
| Line 190: | Line 137: |
| == Dirs == | == Reserved Keywords == |
| Line 192: | Line 139: |
| ---- | Some parts of the language are technically implemented as a command. |
| Line 194: | Line 141: |
| See [[Bash/Looping|here]] for `break` and `continue`. | |
| Line 195: | Line 143: |
| See [[Bash/Function#Error_and_Return_Codes|here]] for `return`. | |
| Line 196: | Line 145: |
| == Disown == | See [[Bash/Completion|here]] for `compgen`, `complete, and `compopt`. |
| Line 198: | Line 147: |
| ---- == Echo == ---- == Enable == ---- == Eval == Executes a command. This is useful when building commands through [[Bash/Expansion#Parameter_Expansion|parameter expansion]]. ---- == Exec == Replaces the shell with the specified command. This is useful in scripts that dispatch to other commands, like `demenu(1)`. ---- == Exit == Causes a script or shell to exit immediately with a specified exit code. If used in an interactive shell, or when used in a script that is `source`d, causes the shell session to exit. That is likely not desireable; see [[#Return|return]] instead. ---- == Export == Marks one or more names as variables to be included in the environment of subsequently-called commands. To set a variable and mark it simultaneously, try: {{{ export varname="some value" }}} To instead export a function, use `export -f funcname` ---- == Fc == ---- == Fg == See [[Bash/JobControl|here]]. ---- == GetOpts == ---- == Hash == ---- == Help == Prints helpful information about a builtin command. {{{ help help }}} ---- == History == ---- == Jobs == See [[Bash/JobControl|here]]. ---- == Kill == ---- == Let == See [[Bash/Arithmetic|here]]. ---- == Local == Only valid within a function definition. See [[Bash/Function#Local_Scope|here]]. ---- == LogOut == Exit a login shell immediately. ---- == MapFile == ---- == PopD == ---- == PrintF == ---- == PushD == ---- == Pwd == Prints the current working directory. ---- == Read == ---- == ReadArray == ---- == ReadOnly == ---- == Return == Only valid within a function definition. See [[Bash/Function#Error_and_Return_Codes|here]]. ---- == Set == See [[Bash/ShellOptions|here]]. ---- == Shift == Renames the [[Bash/Variables#Positional_Variables|special positional variables]]. If `shift` is called with no argument, `$2` is renamed to `$1`, `$3` is renamed to `$2`, and so on. `shift N` causes `$N+1` to be renamed to `$N`, `$N+2` to be renamed to `$N+1`, and so on. ---- == ShOpt == See [[Bash/ShellOptions|here]]. ---- == Source == ---- == Test == Aliased to `[`. See [[Bash/Test|here]]. ---- == Time == ---- == Trap == See [[Bash/Trap|here]]. ---- == TypeSet == ---- == UnAlias == See [[Bash/Alias|here]]. ---- == UnSet == See [[Bash/ShellOptions|here]]. ---- == Wait == |
See [[Bash/JobControl|here]] for `bg`, `coproc`, `fg`, and `jobs`. |
Bash Builtin Commands
The set of portable commands.
Commands
Command |
Description |
Example |
. |
Alias for source |
|
: |
No-op |
|
alias |
Creates an alias |
|
bind |
|
|
builtin |
Executes a builtin command |
|
caller |
|
|
cd |
Changes the current working directory |
|
command |
Executes a command |
|
declare |
Set a variable, optionally with a value |
|
dirs |
|
|
disown |
|
|
echo |
|
|
enable |
|
|
eval |
Executes a command |
|
exec |
Replaces the shell with a command |
|
exit |
Causes a script or shell to exit immediately |
|
export |
Marks one or more names as variables to be included in the environment of subsequently-called commands |
export varname="some value" |
fc |
|
|
getopts |
|
|
hash |
|
|
help |
Prints helpful information about a builtin command |
|
history |
|
|
kill |
|
|
let |
|
|
local |
Only valid within a function definition; see here |
|
logout |
Exits a login shell immediately |
|
mapfile |
|
|
popd |
|
|
printf |
|
|
pushd |
|
|
pwd |
Prints the current working directory |
|
read |
|
|
readarray |
|
|
readonly |
|
|
set |
Sets a shell option |
|
shift |
Renames the positional variables |
|
shopt |
Sets a shell option |
|
source |
|
|
test |
Executes a test |
|
time |
|
|
trap |
Creates a trap |
|
typeset |
|
|
unalias |
Removes an alias |
|
unset |
Unsets a shell option |
|
wait |
|
|
Builtin
builtin can be useful to call a builtin command when there is a custom command with the same name.
Cd
Calling cd without an argument is the same as cd ~.
cd - changes the current working directory to the previous working directory.
Command
command can be useful to call a command when there is a function with the same name.
command is also commonly used to determine if a command is locally available.
if ! command -v mypy >/dev/null 2>&1; then echo "cannot locate mypy; is it installed?" exit fi
Declare
When used within a function definition, the variable is set to local scope.
To create a variable that is marked for export, use:
declare -x myvar
To create a variable that is marked for tracing, use:
declare -t myvar
To create a read-only constant, use:
declare -r myconst
To create an integer variable, use:
declare -i myinteger
To create an array, use:
declare -a myarray
To create an associative array, use:
declare -A myarray
With some exceptions, these options can be combined. Additionally, options can be explicitly disabled by substituting the dash (-) with a plus sign (+).
Reserved Keywords
Some parts of the language are technically implemented as a command.
See here for break and continue.
See here for return.
See here for compgen, complete, and compopt`.
See here for bg, coproc, fg, and jobs.
