COMMAND EXECUTION
The primary prompt ($PS1 - default $ or # for super-users) is displayed whenever the Bourne shell is ready to read a command. The secondary prompt ($PS2 - default >) is displayed when the Bourne shell needs more input.
Command Execution Format
command1 ; command2
| execute command1 followed by command2
|
command &
| execute command asynchronously in the background
|
command1 | command2
| pass the standard output of command1 to standard input of command2
|
command1 && command2
| execute command2 if command1 returns zero (successful) exit status
|
command1 || command2
| execute command2 if command1 returns non-zero (unsuccessful) exit status
|
command \
| continue command onto the next line
|
{ command ; }
| execute command in the current shell
|
( command )
| execute command in a subshell
|
REDIRECTING INPUT/OUTPUT
The Bourne shell provides a number of operators that can be used to manipulate command input/output, and files.
I/O Redirection Operators
<file
| redirect standard input from file
|
>file
| redirect standard output to file. Create file if non-existent, else overwrite.
|
>>file
| append standard output to file; create if non-existent.
|
<&
| close standard input
|
>&
| close standard output
|
<&n
| redirect standard input from file descriptor n
|
>&n
| redirect standard output to file descriptor n
|
n<file
| redirect file descriptor n from file
|
n>file
| redirect file descriptor n to file
|
n>>file
| redirect file descriptor n to file. Create file if non-existent, else overwrite.
|
n<&m
| redirect file descriptor n from file descriptor m
|
n>&m
| redirect file descriptor n to file descriptor m
|
n<<x
| redirect to file descriptor n until x is read
|
n<<x
| same as n<<x, except ignore leading tabs
|
n<&
| close file descriptor n for standard input
|
n>&
| close file descriptor n for standard output
|
FILENAME SUBSTITUTION
File name substitution is a feature which allows special characters and patterns to substituted with file names in the current directory, or arguments to the case and test commands.
Pattern-Matching Characters/Patterns
?
| match any single character
|
*
| match zero or more characters, including null
|
[abc]
| match any characters between the brackets
|
[xz]
| match any characters in the range x to z
|
[aceg]
| match any characters in the range a to c, e to g
|
[!abc]
| match any characters not between the brackets
|
[!xz]
| match any characters not in the range x to z
|
.
| strings starting with . must be explicitly matched
|
VARIABLES
Like in other high-level progamming languages, variables are used by the Bourne shell to store values. Variable names can begin with an alphabetic or underscore character, followed by one or more alphanumeric or underscore characters. Other variable names that contain only digits or special characters are reserved for special variables (called parameters) set directly by the Bourne shell.
Variable Assignment Format
variable=, variable=""
| declare variable and set it to null
|
variable=value
| assign value to variable
|
VARIABLE SUBSTITUTION
Variable values can be accessed and manipulated using variable expansion. Basic expansion is done by preceding the variable name with the $ character. Other types of expansion use default or alternate values, assign default or alternate values, and more.
Variable Expansion Format
$variable
| value of variable
|
${variable}
| value of variable
|
${variable:word}
| value of variable if set and not null, else print word. If >5zWÄmitted, variable is only checked if it is set.
|
${variable:=word}
| value of variable if set and not null, else variable is set to word, then expanded. If : is omitted, variable is only checked if it is set.
|
${variable:?}
| value of variable if set and not null, else print "variable: parameter null or not set". If : is omitted, variable is only checked if it is set.
|
${variable:?word}
| value of variable if set and not null, else print value of word and exit. If : is omitted, variable is only chpOked if it is set:@${variable:+word} value of word if variable is set and not null, else nothing is substituted. If : is omitted, variable is only checked if it is set.
|
|