Previous Table of Contents Next


COMMAND EXECUTION

The primary prompt (PS1 - default $ or # for super-users) is displayed whenever the Korn shell is ready to read a command. The secondary prompt (PS2 - default >) is displayed when the Korn shell needs more input.

Command Execution Format

command1 ; command2 execute command1 followed by command2
command & execute command asynchronously in the background; do not wait for completion
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 |& execute command asynchronously with its standard input and output attached to the parent shell; use read –p/print –p to manipulate the standard input/output
command \ continue command onto the next line
{ command ; } execute command in the current shell
( command ) execute command in a subshell

REDIRECTING INPUT/OUTPUT

The Korn shell provides a number of operators that can be used to manipulate command input/output, files, and co-processes.

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.
>|file redirect standard output to file. Create file if non-existent, else overwrite even if noclobber is set.
<>file open file for reading and writing as standard input
<& 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>|file redirect file descriptor n to file. Create file if non-existent, else overwrite even if noclobber is set.
n<&m redirect file descriptor n from file descriptor m
n>&m redirect file descriptor n to file descriptor m
n<>file open file for reading and writing as file descriptor n
n<<word redirect to file descriptor n until word is read
n<<word redirect to file descriptor n until word is read; ignore leading tabs
n<& close file descriptor n for standard input
n>& close file descriptor n for standard output
n<&p redirect input from co-process to file descriptor n. If n is not specified, use standard input.
n>&p redirect output of co-process to file descriptor n. If n is not specified, use 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 [[...]] commands.

Pattern-Matching Characters/Patterns

? match any single character
* match zero or more characters, including null
[abc] match any characters between the brackets
[x–z] match any character or characters in the range x to z
[a–ce–g] match any characters in the range a to c, e to g
[!abc] match any characters not between the brackets
[!x–z] match any characters not in the range x to z
. strings starting with . must be explicitly matched
?(pattern-list) match zero or one occurrence of any pattern
*(pattern-list) match zero or more occurrences of any pattern
+(pattern-list) match one or more occurrence of any pattern
@(pattern-list) match exactly one occurrence of any pattern
!(pattern-list) match anything except any pattern
pattern-list multiple patterns must be separated with a | character

VARIABLES

Like in other high-level progamming languages, variables are used by the Korn 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 Korn shell. Data types (called attributes) and one-dimensional arrays are also supported by the Korn shell.


Previous Table of Contents Next
1