📄 bashref.html
字号:
</P><P><A NAME="Comments"></A><HR SIZE="6"><A NAME="SEC14"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC13"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> << </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC6"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.1.3 Comments </H3><!--docid::SEC14::--><P>In a non-interactive shell, or an interactive shell in which the<CODE>interactive_comments</CODE> option to the <CODE>shopt</CODE>builtin is enabled (see section <A HREF="bashref.html#SEC57">4.2 Bash Builtin Commands</A>),a word beginning with <SAMP>`#'</SAMP>causes that word and all remaining characters on that line tobe ignored. An interactive shell without the <CODE>interactive_comments</CODE>option enabled does not allow comments. The <CODE>interactive_comments</CODE>option is on by default in interactive shells.See section <A HREF="bashref.html#SEC73">6.3 Interactive Shells</A>, for a description of what makesa shell interactive.</P><P><A NAME="Shell Commands"></A><HR SIZE="6"><A NAME="SEC15"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC16"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> << </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.2 Shell Commands </H2><!--docid::SEC15::--><P>A simple shell command such as <CODE>echo a b c</CODE> consists of the commanditself followed by arguments, separated by spaces.</P><P>More complex shell commands are composed of simple commands arranged togetherin a variety of ways: in a pipeline in which the output of one commandbecomes the input of a second, in a loop or conditional construct, or insome other grouping.</P><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC16">3.2.1 Simple Commands</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">The most common type of command.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC17">3.2.2 Pipelines</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Connecting the input and output of several commands.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC18">3.2.3 Lists of Commands</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to execute commands sequentially.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC19">3.2.4 Looping Constructs</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Shell commands for iterative action.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC20">3.2.5 Conditional Constructs</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Shell commands for conditional execution.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC21">3.2.6 Grouping Commands</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Ways to group commands.</TD></TR></TABLE></BLOCKQUOTE><P><A NAME="Simple Commands"></A><HR SIZE="6"><A NAME="SEC16"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC17"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> << </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.1 Simple Commands </H3><!--docid::SEC16::--><P>A simple command is the kind of command encountered most often.It's just a sequence of words separated by <CODE>blank</CODE>s, terminatedby one of the shell's control operators (see section <A HREF="bashref.html#SEC4">2. Definitions</A>). Thefirst word generally specifies a command to be executed, with therest of the words being that command's arguments.</P><P>The return status (see section <A HREF="bashref.html#SEC52">3.7.5 Exit Status</A>) of a simple command isits exit status as providedby the POSIX 1003.1 <CODE>waitpid</CODE> function, or 128+<VAR>n</VAR> ifthe command was terminated by signal <VAR>n</VAR>.</P><P><A NAME="Pipelines"></A><HR SIZE="6"><A NAME="SEC17"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC16"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC18"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC18"> << </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.2 Pipelines </H3><!--docid::SEC17::--><P>A <CODE>pipeline</CODE> is a sequence of simple commands separated by<SAMP>`|'</SAMP>.</P><P><A NAME="IDX24"></A><A NAME="IDX25"></A><A NAME="IDX26"></A>The format for a pipeline is<TABLE><tr><td> </td><td class=example><pre>[<CODE>time</CODE> [<CODE>-p</CODE>]] [<CODE>!</CODE>] <VAR>command1</VAR> [<CODE>|</CODE> <VAR>command2</VAR> <small>...</small>]</pre></td></tr></table></P><P>The output of each command in the pipeline is connected via a pipeto the input of the next command.That is, each command reads the previous command's output.</P><P>The reserved word <CODE>time</CODE> causes timing statisticsto be printed for the pipeline once it finishes.The statistics currently consist of elapsed (wall-clock) time anduser and system time consumed by the command's execution.The <SAMP>`-p'</SAMP> option changes the output format to that specifiedby POSIX.The <CODE>TIMEFORMAT</CODE> variable may be set to a format string thatspecifies how the timing information should be displayed.See section <A HREF="bashref.html#SEC62">5.2 Bash Variables</A>, for a description of the available formats.The use of <CODE>time</CODE> as a reserved word permits the timing ofshell builtins, shell functions, and pipelines. An external<CODE>time</CODE> command cannot time these easily.</P><P>If the pipeline is not executed asynchronously (see section <A HREF="bashref.html#SEC18">3.2.3 Lists of Commands</A>), theshell waits for all commands in the pipeline to complete.</P><P>Each command in a pipeline is executed in its own subshell(see section <A HREF="bashref.html#SEC50">3.7.3 Command Execution Environment</A>). The exitstatus of a pipeline is the exit status of the last command in thepipeline. If the reserved word <SAMP>`!'</SAMP> precedes the pipeline, theexit status is the logical negation of the exit status of the last command.</P><P><A NAME="Lists"></A><HR SIZE="6"><A NAME="SEC18"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC17"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19"> << </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.3 Lists of Commands </H3><!--docid::SEC18::--><P>A <CODE>list</CODE> is a sequence of one or more pipelines separated by oneof the operators <SAMP>`;'</SAMP>, <SAMP>`&'</SAMP>, <SAMP>`&&'</SAMP>, or <SAMP>`||'</SAMP>,and optionally terminated by one of <SAMP>`;'</SAMP>, <SAMP>`&'</SAMP>, or a<CODE>newline</CODE>.</P><P>Of these list operators, <SAMP>`&&'</SAMP> and <SAMP>`||'</SAMP>have equal precedence, followed by <SAMP>`;'</SAMP> and <SAMP>`&'</SAMP>,which have equal precedence.</P><P>A sequence of one or more newlines may appear in a <CODE>list</CODE>to delimit commands, equivalent to a semicolon.</P><P>If a command is terminated by the control operator <SAMP>`&'</SAMP>,the shell executes the command asynchronously in a subshell.This is known as executing the command in the <VAR>background</VAR>.The shell does not wait for the command to finish, and the returnstatus is 0 (true).When job control is not active (see section <A HREF="bashref.html#SEC86">7. Job Control</A>),the standard input for asynchronous commands, in the absence of anyexplicit redirections, is redirected from <CODE>/dev/null</CODE>.</P><P>Commands separated by a <SAMP>`;'</SAMP> are executed sequentially; the shellwaits for each command to terminate in turn. The return status is theexit status of the last command executed.</P><P>The control operators <SAMP>`&&'</SAMP> and <SAMP>`||'</SAMP>denote AND lists and OR lists, respectively.An AND list has the form<TABLE><tr><td> </td><td class=example><pre><VAR>command1</VAR> && <VAR>command2</VAR></pre></td></tr></table></P><P><VAR>command2</VAR> is executed if, and only if, <VAR>command1</VAR>returns an exit status of zero.</P><P>An OR list has the form<TABLE><tr><td> </td><td class=example><pre><VAR>command1</VAR> || <VAR>command2</VAR></pre></td></tr></table></P><P><VAR>command2</VAR> is executed if, and only if, <VAR>command1</VAR>returns a non-zero exit status.</P><P>The return status ofAND and OR lists is the exit status of the last commandexecuted in the list.</P><P><A NAME="Looping Constructs"></A><HR SIZE="6"><A NAME="SEC19"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC18"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC20"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC20"> << </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.4 Looping Constructs </H3><!--docid::SEC19::--><P>Bash supports the following looping constructs.</P><P>Note that wherever a <SAMP>`;'</SAMP> appears in the description of acommand's syntax, it may be replaced with one or more newlines.</P><P><DL COMPACT><DT><CODE>until</CODE><DD><A NAME="IDX27"></A><A NAME="IDX28"></A><A NAME="IDX29"></A>The syntax of the <CODE>until</CODE> command is:<TABLE><tr><td> </td><td class=example><pre>until <VAR>test-commands</VAR>; do <VAR>consequent-commands</VAR>; done</pre></td></tr></table>Execute <VAR>consequent-commands</VAR> as long as<VAR>test-commands</VAR> has an exit status which is not zero.The return status is the exit status of the last command executedin <VAR>consequent-commands</VAR>, or zero if none was executed.<P><DT><CODE>while</CODE><DD><A NAME="IDX30"></A>The syntax of the <CODE>while</CODE> command is:<TABLE><tr><td> </td><td class=example><pre>while <VAR>test-commands</VAR>; do <VAR>consequent-commands</VAR>; done</pre></td></tr></table><P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -