The Bourne Shell offers a large number of built-in commands that you can use in your shell scripts. The following table gives an overview:

Bourne Shell command reference
CommandDescription
:A null command that returns a 0 (true) exit value.
. fileExecute. The commands in the specified file are read and executed by the shell. Commonly referred to as sourcing a file.
#Ignore all the text until the end of the line. Used to create comments in shell scripts.
#!shellInterpreter hint. Indicates to the OS which interpreter to use to execute a script.
bg [job] ...Run the specified jobs (or the current job if no arguments are given) in the background.
break [n]Break out of a loop. If a number argument is specified, break out of n levels of loops.
caseSee Bourne_Shell_Scripting/Control_flow
cd [directory]Switch to the specified directory (default $HOME).
continue [n]Skip the remaining commands in a loop and continue the loop at the next interation. If an integer argument is specified, skip n loops.
echo stringWrite string to the standard output.
eval string ...Concatenate all the arguments with spaces. Then re-parse and execute the command.
exec [command arg ...]Execute command in the current process.
exit [exitstatus]Terminate the shell process. If exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the last completed command is used.
export name ...Mark the named variables or functions for export to child process environments.
fg [job]Move the specified job (or the current job if not specified) to the foreground.
forSee Bourne_Shell_Scripting/Control_flow.
hash -rv command ...The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid.

With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. The -r option causes the hash command to delete all the entries in the hash table except for functions.

ifSee Bourne_Shell_Scripting/Control_flow.
jobsThis command lists out all the background processes which are children of the current shell process.
-signal] PID ...Send signal to the jobs listed by ID. If no signal is specified, send SIGTERM.

If the -l option is used, lists all the signal names defined on the system.

newgrp [group]Temporarily move your user to a new group. If no group is listed, move back to your user's default group.
pwdPrint the working directory.
read variable [...]Read a line from the input and assign each individual word to a listed variable (in order). Any leftover words are assigned to the last variable.
readonly name ...Make the listed variables read-only.
return [n]Return from a shell function. If an integer argument is specified it will be the exit status of the function.
set [{ -options | +options | -- }] arg ...The set command performs three different functions.

With no arguments, it lists the values of all shell variables.

If options are given, it sets the specified option flags or clears them.

The third use of the set command is to set the values of the shell's positional parameters to the specified args. To change the positional parameters without changing any options, use “--” as the first argument to set. If no args are present, the set command will clear all the positional parameters (equivalent to executing “shift $#”.)

shift [n]Shift the positional parameters n times.
testSee Bourne_Shell_Scripting/Control_flow.
trap [action] signal ...Cause the shell to parse and execute action when any of the specified signals are received.
type [name ...]Show whether a command is a UNIX command, a shell built-in command or a shell function.
ulimitReport on or set resource limits.
umask [mask]Set the value of umask (the mask for the default file permissions not assigned to newly created files). If the argument is omitted, the umask value is printed.
unset name ...Drop the definition of the given names in the shell.
wait [job]Wait for the specified job to complete and return the exit status of the last process in the job. If the argument is omitted, wait for all jobs to complete and the return an exit status of zero.
whileSee Bourne_Shell_Scripting/Control_flow.
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.