Differences between revisions 2 and 3
Revision 2 as of 2023-01-30 01:03:27
Size: 3921
Comment:
Revision 3 as of 2025-12-19 20:18:28
Size: 2872
Comment: Reorg
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:
---- ||'''Command''' ||'''Description'''||'''Example'''||
||`.` || || ||
||`:` ||No-op || ||
||`alias` ||Creates an [[Shell/Alias|alias]]|| ||
||`bind` || || ||
||`builtin` ||Executes a builtin command|| ||
||`cd` ||Changes the current working directory|| ||
||`command` ||Executes a command|| ||
||`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` || || ||
||`logout` ||Exits a login shell immediately|| ||
||`mapfile` || || ||
||`popd` || || ||
||`printf` || || ||
||`pushd` || || ||
||`pwd` ||Prints the current working directory|| ||
||`read` || || ||
||`readarray` || || ||
||`readonly` || || ||
||`set` ||Sets a [[Shell/ShellOptions|shell option]]|| ||
||`shift` ||Renames the [[Shell/Variables#Positional_Variables|positional variables]]|| ||
||`test` ||Executes a [[Shell/Test|test]]|| ||
||`time` || || ||
||`trap` ||Creates a [[Shell/Trap|here]]|| ||
||`typeset` || || ||
||`unalias` ||Removes an [[Shell/Alias|alias]]|| ||
||`unset` ||Unsets a [[Shell/ShellOptions|shell option]]|| ||
||`wait` || || ||
Line 15: Line 56:
== : == === Builtin ===
Line 17: Line 58:
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 23: Line 62:
== Alias == === Cd ===
Line 25: Line 64:
See [[Shell/Alias|here]]. Calling `cd` without an argument is the same as `cd ~`.
Line 27: Line 66:
---- `cd -` changes the current working directory to the previous working directory.
Line 31: Line 70:
== Bg == === Command ===
Line 33: Line 72:
See [[Shell/JobControl|here]]. `command` can be useful to call a command when there is a function with the same name.
Line 35: Line 74:
----



== Bind ==

----



== Break ==

See [[Shell/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 [[Shell/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 96: Line 87:
== Continue == == Reserved Keywords ==
Line 98: Line 89:
See [[Shell/Looping|here]]. Some parts of the language are technically implemented as a command.
Line 100: Line 91:
---- See [[Shell/Looping|here]] for `break` and `continue`.
Line 102: Line 93:
See [[Shell/Function#Error_and_Return_Codes|here]] for `return`.
Line 103: Line 95:

== Dirs ==

----



== Disown ==

----



== Echo ==

----



== Enable ==

----



== Eval ==

Executes a command. This is useful when building commands through [[Shell/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 [[Shell/JobControl|here]].

----



== GetOpts ==

----



== Hash ==

----



== Help ==

Prints helpful information about a builtin command.

{{{
help help
}}}

----



== History ==

----



== Jobs ==

See [[Shell/JobControl|here]].

----



== Kill ==

----



== 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 [[Shell/Function#Error_and_Return_Codes|here]].

----



== Set ==

See [[Shell/ShellOptions|here]].

----



== Shift ==

Renames the [[Shell/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.

----



== Test ==

Aliased to `[`.

See [[Shell/Test|here]].

----



== Time ==

----



== Trap ==

See [[Shell/Trap|here]].

----



== TypeSet ==

----



== UnAlias ==

See [[Shell/Alias|here]].

----



== UnSet ==

See [[Shell/ShellOptions|here]].

----



== Wait ==
See [[Shell/JobControl|here]] for `bg`, `fg`, and `jobs`.

Shell Builtin Commands

The set of portable commands.


Commands

Command

Description

Example

.

:

No-op

alias

Creates an alias

bind

builtin

Executes a builtin command

cd

Changes the current working directory

command

Executes a command

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

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

test

Executes a test

time

trap

Creates a here

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


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 bg, fg, and jobs.


CategoryRicottone

Shell/BuiltinCommands (last edited 2025-12-19 20:19:12 by DominicRicottone)