📄 bash.0
字号:
_e_x_p_r_e_s_s_i_o_n_1 |||| _e_x_p_r_e_s_s_i_o_n_2 True if either _e_x_p_r_e_s_s_i_o_n_1 or _e_x_p_r_e_s_s_i_o_n_2 is true. The &&&& and |||| operators do not evaluate _e_x_p_r_e_s_s_i_o_n_2 if the value of _e_x_p_r_e_s_s_i_o_n_1 is sufficient to determine the return value of the entire conditional expression. ffoorr _n_a_m_e [ [ iinn [ _w_o_r_d _._._. ] ] ; ] ddoo _l_i_s_t ; ddoonnee The list of words following iinn is expanded, generating a list of items. The variable _n_a_m_e is set to each element of this list in turn, and _l_i_s_t is executed each time. If the iinn _w_o_r_d is omit- ted, the ffoorr command executes _l_i_s_t once for each positional parameter that is set (see PPAARRAAMMEETTEERRSS below). The return status is the exit status of the last command that executes. If the expansion of the items following iinn results in an empty list, no commands are executed, and the return status is 0. ffoorr (( _e_x_p_r_1 ; _e_x_p_r_2 ; _e_x_p_r_3 )) ; ddoo _l_i_s_t ; ddoonnee First, the arithmetic expression _e_x_p_r_1 is evaluated according to the rules described below under AARRIITTHHMMEETTIICC EEVVAALLUUAATTIIOONN. The arithmetic expression _e_x_p_r_2 is then evaluated repeatedly until it evaluates to zero. Each time _e_x_p_r_2 evaluates to a non-zero value, _l_i_s_t is executed and the arithmetic expression _e_x_p_r_3 is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in _l_i_s_t that is executed, or false if any of the expres- sions is invalid. sseelleecctt _n_a_m_e [ iinn _w_o_r_d ] ; ddoo _l_i_s_t ; ddoonnee The list of words following iinn is expanded, generating a list of items. The set of expanded words is printed on the standard error, each preceded by a number. If the iinn _w_o_r_d is omitted, the positional parameters are printed (see PPAARRAAMMEETTEERRSS below). The PPSS33 prompt is then displayed and a line read from the stan- dard input. If the line consists of a number corresponding to one of the displayed words, then the value of _n_a_m_e is set to that word. If the line is empty, the words and prompt are dis- played again. If EOF is read, the command completes. Any other value read causes _n_a_m_e to be set to null. The line read is saved in the variable RREEPPLLYY. The _l_i_s_t is executed after each selection until a bbrreeaakk command is executed. The exit status of sseelleecctt is the exit status of the last command executed in _l_i_s_t, or zero if no commands were executed. ccaassee _w_o_r_d iinn [ [(] _p_a_t_t_e_r_n [ || _p_a_t_t_e_r_n ] ... ) _l_i_s_t ;; ] ... eessaacc A ccaassee command first expands _w_o_r_d, and tries to match it against each _p_a_t_t_e_r_n in turn, using the same matching rules as for path- name expansion (see PPaatthhnnaammee EExxppaannssiioonn below). The _w_o_r_d is expanded using tilde expansion, parameter and variable expan- sion, arithmetic substitution, command substitution, process substitution and quote removal. Each _p_a_t_t_e_r_n examined is expanded using tilde expansion, parameter and variable expan- sion, arithmetic substitution, command substitution, and process substitution. If the shell option nnooccaasseemmaattcchh is enabled, the match is performed without regard to the case of alphabetic characters. When a match is found, the corresponding _l_i_s_t is executed. If the ;;;; operator is used, no subsequent matches are attempted after the first pattern match. Using ;;&& in place of ;;;; causes execution to continue with the _l_i_s_t associated with the next set of patterns. Using ;;;;&& in place of ;;;; causes the shell to test the next pattern list in the statement, if any, and execute any associated _l_i_s_t on a successful match. The exit status is zero if no pattern matches. Otherwise, it is the exit status of the last command executed in _l_i_s_t. iiff _l_i_s_t; tthheenn _l_i_s_t_; [ eelliiff _l_i_s_t; tthheenn _l_i_s_t; ] ... [ eellssee _l_i_s_t; ] ffii The iiff _l_i_s_t is executed. If its exit status is zero, the tthheenn _l_i_s_t is executed. Otherwise, each eelliiff _l_i_s_t is executed in turn, and if its exit status is zero, the corresponding tthheenn _l_i_s_t is executed and the command completes. Otherwise, the eellssee _l_i_s_t is executed, if present. The exit status is the exit sta- tus of the last command executed, or zero if no condition tested true. wwhhiillee _l_i_s_t_-_1; ddoo _l_i_s_t_-_2; ddoonnee uunnttiill _l_i_s_t_-_1; ddoo _l_i_s_t_-_2; ddoonnee The wwhhiillee command continuously executes the list _l_i_s_t_-_2 as long as the last command in the list _l_i_s_t_-_1 returns an exit status of zero. The uunnttiill command is identical to the wwhhiillee command, except that the test is negated; _l_i_s_t_-_2 is executed as long as the last command in _l_i_s_t_-_1 returns a non-zero exit status. The exit status of the wwhhiillee and uunnttiill commands is the exit status of the last command executed in _l_i_s_t_-_2, or zero if none was exe- cuted. CCoopprroocceesssseess A _c_o_p_r_o_c_e_s_s is a shell command preceded by the ccoopprroocc reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the && control operator, with a two-way pipe established between the executing shell and the coprocess. The format for a coprocess is: ccoopprroocc [_N_A_M_E] _c_o_m_m_a_n_d [_r_e_d_i_r_e_c_t_i_o_n_s] This creates a coprocess named _N_A_M_E. If _N_A_M_E is not supplied, the default name is _C_O_P_R_O_C. _N_A_M_E must not be supplied if _c_o_m_m_a_n_d is a _s_i_m_- _p_l_e _c_o_m_m_a_n_d (see above); otherwise, it is interpreted as the first word of the simple command. When the coproc is executed, the shell creates an array variable (see AArrrraayyss below) named _N_A_M_E in the context of the executing shell. The standard output of _c_o_m_m_a_n_d is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to _N_A_M_E[0]. The standard input of _c_o_m_m_a_n_d is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to _N_A_M_E[1]. This pipe is established before any redirections specified by the command (see RREEDDIIRREECCTTIIOONN below). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. The process ID of the shell spawned to execute the coprocess is available as the value of the variable _N_A_M_E_PID. The wwaaiitt builtin command may be used to wait for the coprocess to terminate. The return status of a coprocess is the exit status of _c_o_m_m_a_n_d. SShheellll FFuunnccttiioonn DDeeffiinniittiioonnss A shell function is an object that is called like a simple command and executes a compound command with a new set of positional parameters. Shell functions are declared as follows: _n_a_m_e () _c_o_m_p_o_u_n_d_-_c_o_m_m_a_n_d [_r_e_d_i_r_e_c_t_i_o_n] ffuunnccttiioonn _n_a_m_e [()] _c_o_m_p_o_u_n_d_-_c_o_m_m_a_n_d [_r_e_d_i_r_e_c_t_i_o_n] This defines a function named _n_a_m_e. The reserved word ffuunnccttiioonn is optional. If the ffuunnccttiioonn reserved word is supplied, the parentheses are optional. The _b_o_d_y of the function is the com- pound command _c_o_m_p_o_u_n_d_-_c_o_m_m_a_n_d (see CCoommppoouunndd CCoommmmaannddss above). That command is usually a _l_i_s_t of commands between { and }, but may be any command listed under CCoommppoouunndd CCoommmmaannddss above. _c_o_m_- _p_o_u_n_d_-_c_o_m_m_a_n_d is executed whenever _n_a_m_e is specified as the name of a simple command. Any redirections (see RREEDDIIRREECCTTIIOONN below) specified when a function is defined are performed when the function is executed. The exit status of a function definition is zero unless a syntax error occurs or a readonly function with the same name already exists. When executed, the exit status of a function is the exit status of the last command executed in the body. (See FFUUNNCCTTIIOONNSS below.)CCOOMMMMEENNTTSS In a non-interactive shell, or an interactive shell in which the iinntteerr-- aaccttiivvee__ccoommmmeennttss option to the sshhoopptt builtin is enabled (see SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS below), a word beginning with ## causes that word and all remaining characters on that line to be ignored. An interactive shell without the iinntteerraaccttiivvee__ccoommmmeennttss option enabled does not allow comments. The iinntteerraaccttiivvee__ccoommmmeennttss option is on by default in interac- tive shells.QQUUOOTTIINNGG _Q_u_o_t_i_n_g is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, to prevent reserved words from being recognized as such, and to prevent parameter expansion. Each of the _m_e_t_a_c_h_a_r_a_c_t_e_r_s listed above under DDEEFFIINNIITTIIOONNSS has special meaning to the shell and must be quoted if it is to represent itself. When the command history expansion facilities are being used (see HHIISS-- TTOORRYY EEXXPPAANNSSIIOONN below), the _h_i_s_t_o_r_y _e_x_p_a_n_s_i_o_n character, usually !!, must be quoted to prevent history expansion. There are three quoting mechanisms: the _e_s_c_a_p_e _c_h_a_r_a_c_t_e_r, single quotes, and double quotes. A non-quoted backslash (\\) is the _e_s_c_a_p_e _c_h_a_r_a_c_t_e_r. It preserves the literal value of the next character that follows, with the exception of <newline>. If a \\<newline> pair appears, and the backslash is not itself quoted, the \\<newline> is treated as a line continuation (that is, it is removed from the input stream and effectively ignored). Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $$, ``, \\, and, when history expansion is enabled, !!. The characters $$ and `` retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: $$, ``, "", \\, or <<nneewwlliinnee>>. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an !! appearing in double quotes is escaped using a backslash. The backslash preceding the !! is not removed. The special parameters ** and @@ have special meaning when in double quotes (see PPAARRAAMMEETTEERRSS below). Words of the form $$'_s_t_r_i_n_g' are treated specially. The word expands to _s_t_r_i_n_g, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: \\aa alert (bell) \\bb backspace \\ee \\EE an escape character \\ff form feed \\nn new line \\rr carriage return \\tt horizontal tab
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -