📄 a
字号:
can be started. If a command is followed by & and job control is inactive, the default standard input for the command is the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications. Environment The environment (see environ(5)) is a list of name-value pairs passed to an executed program much like a normal argument list. The names must be identifiers and the values are character strings. The shell interacts with the environment in several ways. When invoked, the shell scans the environment and creates a parameter for each name found, gives it the corresponding value, and marks it export. Executed commands inherit the environment. If the user modifies the values of these parameters or creates new ones by using the export or typeset -x commands, the values become part of the environment. The environment seen by any executed command is thus composed of any name-value pairs originally inherited by the shell whose values can be modified by the current shell, plus any additions which must be noted in export or typeset -x commands. The environment for any simple-command or function can be augmented by prefixing it with one or more parameter assignments. A parameter assignment argument takes the form identifier=value. For example, TERM=450 cmd args and (export TERM; TERM=450; cmd args) are equivalent (as far as the above execution of cmd is concerned except for special commands listed below that are preceded by a percent sign). If the -k option is set, all parameter assignment arguments are placed in the environment, even if they occur after the command name. The following echo statement prints a=b c. After the -k option is set, the second echo statement prints only c: echo a=b c set -k echo a=b c Hewlett-Packard Company - 16 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) This feature is intended for use with scripts written for early versions of the shell, and its use in new scripts is strongly discouraged. It is likely to disappear someday. Functions The function keyword (described in the Commands section above) is used to define shell functions. Shell functions are read and stored internally. Alias names are resolved when the function is read. Functions are executed like commands, with the arguments passed as positional parameters (see Execution below). Functions execute in the same process as the caller except that command substitution of a function creates a new process. Functions share all files and present working directory with the caller. Traps caught by the caller are reset to their default action inside the function. If a function does not catch or specifically ignore a trap condition, the function terminates and the condition is passed on to the caller. A trap on EXIT set inside a function is executed after the function completes in the environment of the caller. Ordinarily, variables are shared between the calling program and the function. However, the typeset special command used within a function defines local variables whose scope includes the current function and all functions it calls. The special command return is used to return from function calls. Errors within functions return control to the caller. Function identifiers can be listed with the +f option of the typeset special command. Function identifiers and the associated text of the functions can be listed with the -f option. Functions can be undefined with the -f option of the unset special command. Ordinarily, functions are unset when the shell executes a shell script. The -xf option of the typeset command allows a function to be exported to scripts that are executed without reinvoking the shell. Functions that must be defined across separate invocations of the shell should be placed in the ENV file. Jobs If the monitor option of the set command is turned on, an interactive shell associates a job with each pipeline. It keeps a table of current jobs, printed by the jobs command, and assigns them small integer numbers. When a job is started asynchronously with &, the shell prints a line resembling: [1] 1234 indicating that job number 1 was started asynchronously and had one (top-level) process whose process ID was 1234. Hewlett-Packard Company - 17 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) If you are running a job and want to do something else, type the suspend character (usually ^Z (Ctrl-Z)) to send a STOP signal to the current job. The shell then indicates that the job has been `Stopped', and prints another prompt. The state of this job can be manipulated by using the bg command to put it in the background, running other commands (while it is stopped or running in the background), and eventually restarting or returning the job to the foreground by using the fg command. A ^Z takes effect immediately and resembles an interrupt, since pending output and unread input are discarded when ^Z is typed. A job run in the background stops if it tries to read from the terminal. Background jobs normally are allowed to produce output, but can be disabled by giving the stty tostop command. If the user sets this tty option, background jobs stop when trying to produce output. There are several ways to refer to jobs in the shell. A job can be referred to by the process ID of any process in the job or by one of the following: %number The job with the given number. %string Any job whose command line begins with string. %?string Any job whose command line contains string. %% Current job. %+ Equivalent to %%. %- Previous job. The shell learns immediately when a process changes state. It informs the user when a job is blocked and prevented from further progress, but only just before it prints a prompt. When the monitor mode is on, each background job that completes triggers any trap set for CHLD. Attempting to leave the shell while jobs are running or stopped produces the warning, You have stopped (running) jobs. Use the jobs command to identify them. An immediate attempt to exit again terminates the stopped jobs; the shell does not produce a warning the second time. Signals The INT and QUIT signals for an invoked command are ignored if the command is followed by & and the monitor option is off. Otherwise, signals have the values inherited by the shell from its parent, with the exception of signal 11 (but see also the trap command below). Execution Substitutions are made each time a command is executed. If the command name matches one of the Special Commands listed below, it is executed within the current shell process. Next, ksh checks the Hewlett-Packard Company - 18 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) command name to determine whether it matches one of the user-defined functions. If it does, ksh saves the positional parameters and then sets them to the arguments of the function call. The positional parameter 0 is set to the function name. When the function completes or issues a return, ksh restores the positional parameter list and executes any trap set on EXIT within the function. The value of a function is the value of the last command executed. A function is executed in the current shell process. If a command name is not a special command or a user-defined function, ksh creates a process and attempts to execute the command using exec (see exec(2)). The shell parameter PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The default path is /usr/bin: (specifying /usr/bin and the current directory in that order). Note that the current directory is specified by a null path name which can appear immediately after the equals sign, between colon delimiters, or at the end of the path list. The search path is not used if the command name contains a /. Otherwise, each directory in the path is searched for an executable file. If the file has execute permissions but is not a directory or an executable object code file, it is assumed to be a script file, which is a file of data for an interpreter. If the first two characters of the script file are #!, exec (see exec(2)) expects an interpreter path name to follow. exec then attempts to execute the specified interpreter as a separate process to read the entire script file. If a call to exec fails, /usr/bin/ksh is spawned to interpret the script file. All non-exported aliases, functions, and named parameters are removed in this case. If the shell command file does not have read permission, or if the setuid and/or setgid bits are set on the file, the shell executes an agent to set up the permissions and execute the shell with the shell command file passed down as an open file. A parenthesized command is also executed in a sub-shell without removing non-exported quantities. Command Re-entry The text of the last HISTSIZE (default 128) commands entered from a terminal device is saved in a history file. The file $HOME/.sh_history is used if the HISTFILE variable is not set or writable. A shell can access the commands of all interactive shells that use the same named HISTFILE. The special command fc is used to list or edit a portion of this file. The portion of the file to be edited or listed can be selected by number or by giving the first character or characters of the command. A single command or range of commands can be specified. If no editor program is specified as an argument to fc, the value of the FCEDIT parameter is used. If FCEDIT is not defined, /usr/bin/ed is used. The edited command is printed and re-executed upon leaving the editor. The editor name - is used to skip the editing phase and to re-execute the command. In this case a substitution parameter of the form old=new can be used to modify the command before execution. For example, if r is aliased to fc -e -, typing r bad=good c re-executes the most recent command that starts Hewlett-Packard Company - 19 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) with the letter c and replaces the first occurrence of the string bad with the string good. The history file will be trimmed when all of the following conditions occurs: Its size is greater than four kilobytes. The number of commands in it is more than HISTSIZE. The file has not been modified in the last ten minutes. The user has write permission for the directory in which the history file resides. If any one of the above conditions does not occur, the history file will not be trimmed. When the history file is trimmed, the latest HISTSIZE commands will be available in the history file. Special Commands The following simple-commands are executed in the shell process. They permit input/output redirection. Unless otherwise indicated, file descriptor 1 is the default output location and the exit status, when there are no syntax errors, is zero. Commands that are preceded by % or %% are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Certain errors cause a script that contains them to abort. 4. Words following a command preceded by %% that are in the format of a variable assignment are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. % : [arg ...] The command only expands parameters. A zero exit code is returned. % . file [arg ...] Read and execute commands from file and return. The commands are executed in the current shell environment. The search path specified by PATH is used to find the directory containing file. If any arguments arg are given, they become the positional parameters. Otherwise the positional parameters are unchanged. The exit status is the exit status of the last command executed. It is not necessary that the execute permission bit be set for file. Hewlett-Packard Company - 20 - HP-UX 11i Version 1: Sep 2002 ksh(1) ksh(1) %% alias [-tx] [name[=value] ...] alias with no arguments prints the list of aliases in the form name=value on standard output. An alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias substitution. The -t option is used to set and list tracked aliases. The value of a tracked alias is the full path name corresponding to the given name.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -