📄 a
字号:
ksh(1) ksh(1) NAME ksh, rksh - shell, the standard/restricted command programming language SYNOPSIS ksh [-aefhikmnoprstuvx] [+aefhikmnoprstuvx] [-o option] ... [+o option] ... [-c string] [arg ...] rksh [-aefhikmnoprstuvx] [+aefhikmnoprstuvx] [-o option] ... [+o option] ... [-c string] [arg ...] DESCRIPTION ksh is a command programming language that executes commands read from a terminal or a file. rksh is a restricted version of the command interpreter ksh, used to set up login names and execution environments whose capabilities are more controlled than those of the standard shell. See Invoking ksh and Special Commands sections later in this entry for details about command line options and arguments, particularly the set command. Definitions metacharacter One of the following characters: ; & ( ) | < > new-line space tab blank A tab or space character. identifier A sequence of letters, digits, or underscores starting with a letter or underscore. Identifiers are used as names for functions and named parameters. word A sequence of characters separated by one or more non- quoted metacharacters . command A sequence of characters in the syntax of the shell language. The shell reads each command and carries out the desired action, either directly or by invoking separate utilities. special command A command that is carried out by the shell without creating a separate process. Often called ``built-in commands''. Except for documented side effects, most special commands can be implemented as separate utilities. # The # character is interpreted as the beginning of a comment. See Quoting below. Commands A simple-command is a sequence of blank-separated words that can be Hewlett-Packard Company - 1 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) preceded by a parameter assignment list. (See Environment below). The first word specifies the name of the command to be executed. Except as specified below, the remaining words are passed as arguments to the invoked command. The command name is passed as argument 0 (see exec(2)). The value of a simple-command is its exit status if it terminates normally, or (octal) 200+status if it terminates abnormally (see signal(5) for a list of status values). A pipeline is a sequence of one or more commands separated by |. The standard output of each command except the last is connected by a pipe (see pipe(2)) to the standard input of the next command. Each command is run as a separate process; the shell waits for the last command to terminate. The exit status of a pipeline is the exit status of the last command in the pipeline. A list is a sequence of one or more pipelines separated by ;, &, &&, or ||, and optionally terminated by ;, &, or |&. Of these five symbols, ;, &, and |& have equal precedence. && and || have a higher but also equal precedence. A semicolon (;) causes sequential execution of the preceding pipeline; an ampersand (&) causes asynchronous execution of the preceding pipeline (that is, the shell does not wait for that pipeline to finish). The symbol |& causes asynchronous execution of the preceding command or pipeline with a two-way pipe established to the parent shell (known as a co-process). The standard input and output of the spawned command can be written to and read from by the parent shell using the -p option of the special commands read and print described later. The symbol && (||) causes the list following it to be executed only if the preceding pipeline returns a zero (non-zero) value. An arbitrary number of new-lines can appear in a list, instead of semicolons, to delimit commands. A command is either a simple-command or one of the following. Unless otherwise stated, the value returned by a command is that of the last simple-command executed in the command. for identifier [in word ...] do list done Each time for is executed, identifier is set to the next word taken from the in word list. If in word ... is omitted, for executes the do list once for each positional parameter set (see Parameter Substitution below). Execution ends when there are no more words in the list. select identifier [in word...] do list done A select command prints on standard error (file descriptor 2), the set of words, each preceded by a number. If in word ... is omitted, the positional parameters are used instead (see Parameter Substitution below). The PS3 prompt is printed and a line is read from the standard input. If this line starts with the number of one of the listed words, the value of the Hewlett-Packard Company - 2 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) parameter identifier is set to the word corresponding to this number. If this line is empty, the selection list is printed again. Otherwise the value of the parameter identifier is set to null. The contents of the line read from standard input is saved in the parameter REPLY. The list is executed for each selection until a break or end-of-file (eof) is encountered. case word in [[ (] pattern [ | pattern] ... ) list ;; ] ... esac A case command executes the list associated with the first pattern that matches word. The form of the patterns is identical to that used for file name generation (see File Name Generation below). if list then list [ elif list then list] ... [ else list] fi The list following if is executed and, if it returns a zero exit status, the list following the first then is executed. Otherwise, the list following elif is executed and, if its value is zero, the list following the next then is executed. Failing that, the else list is executed. If no else list or then list is executed, if returns a zero exit status. while list do list done until list do list done A while command repeatedly executes the while list, and if the exit status of the last command in the list is zero, executes the do list; otherwise the loop terminates. If no commands in the do list are executed, while returns a zero exit status; until can be used in place of while to negate the loop termination test. (list) Execute list in a separate environment. If two adjacent open parentheses are needed for nesting, a space must be inserted to avoid arithmetic evaluation as described below. { list;} Execute list, but not in a separate environment. Note that { is a keyword and requires a trailing blank to be recognized. [[ expression ]] Evaluates expression and returns a zero exit status when expression is true. See Conditional Expressions below, for a description of expression. Note that [[ and ]] are keywords and require blanks between them and expression. Hewlett-Packard Company - 3 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) function identifier {list;} identifier () {list;} Define a function referred to by identifier. The body of the function is the list of commands between { and } (see Functions below). time pipeline pipeline is executed and the elapsed time, user time, and system time are printed on standard error. Note that the time keyword can appear anywhere in the pipeline to time the entire pipeline. To time a particular command in a pipeline, see time(1). The following keywords are recognized only as the first word of a command and when not quoted: if then else elif fi case esac for while until do done { } function select time [[ ]] Comments A word beginning with # causes that word and all subsequent characters up to a new-line to be ignored. Aliasing The first word of each command is replaced by the text of an alias, if an alias for this word has been defined. An alias name consists of any number of characters excluding metacharacters, quoting characters, file expansion characters, parameter and command substitution characters, and =. The replacement string can contain any valid shell script, including the metacharacters listed above. The first word of each command in the replaced text, other than any that are in the process of being replaced, is tested for additional aliases. If the last character of the alias value is a blank, the word following the alias is also checked for alias substitution. Aliases can be used to redefine special built-in commands, but cannot be used to redefine the keywords listed above. Aliases can be created, listed, and exported with the alias command and can be removed with the unalias command. Exported aliases remain in effect for subshells but must be reinitialized for separate invocations of the shell (see Invoking ksh below). Aliasing is performed when scripts are read, not while they are executed. Therefore, for it to take effect, alias must be executed before the command referring to the alias is read. Aliases are frequently used as a shorthand for full path names. An option to the aliasing facility allows the value of the alias to be automatically set to the full path name of the corresponding command. These aliases are called tracked aliases. The value of a tracked alias is defined the first time the identifier is read and becomes undefined each time the PATH variable is reset. These aliases remain tracked so that the next reference redefines the value. Several Hewlett-Packard Company - 4 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) tracked aliases are compiled into the shell. The -h option of the set command converts each command name that is an identifier into a tracked alias. The following exported aliases are compiled into the shell but can be unset or redefined: autoload='typeset -fu' false='let 0' functions='typeset -f' hash='alias -t -' history='fc -l' integer='typeset -i' nohup='nohup ' r='fc -e -' stop='kill -STOP' suspend='kill -STOP $$' true=':' type='whence -v' Tilde Substitution After alias substitution is performed, each word is checked to see if it begins with an unquoted ~. If it does, the word up to a / is checked to see if it matches a user name in the /etc/passwd file. If a match is found, the ~ and the matched login name are replaced by the login directory of the matched user. This is called a tilde substitution. If no match is found, the original text is left unchanged. A ~, alone or before a /, is replaced by the value of the HOME parameter. A ~ followed by a + or - is replaced by the value of the parameter PWD and OLDPWD, respectively. In addition, tilde substitution is attempted when the value of a parameter assignment begins with a ~. Command Substitution The standard output from a command enclosed in parenthesis preceded by a dollar sign ($(command)) or a pair of back single quotes (accent grave) (`command`) can be used as part or all of a word; trailing new-lines are removed. In the second (archaic) form, the string between the quotes is processed for special quoting characters before the command is executed (see Quoting below). The command substitution $(cat file) can be replaced by the equivalent but faster $(<file). Command substitution of most special commands (built-ins) that do not perform I/O redirection are carried out without creating a separate process. However, command substitution of a function creates a separate process to execute the function and all commands (built-in or otherwise) in that function. An arithmetic expression enclosed in double parenthesis preceded by a dollar sign ($((expression))) is replaced by the value of the arithmetic expression within the double parenthesis (see Arithmetic Evaluation below for a description of arithmetic expressions). Hewlett-Packard Company - 5 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -