265 lines
3.7 KiB
HTML
265 lines
3.7 KiB
HTML
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Performing more than one command</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="GNU/Linux Command-Line Tools Summary"
|
|
HREF="book1.htm"><LINK
|
|
REL="UP"
|
|
TITLE="Directing Input/Output"
|
|
HREF="c2269.htm"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Command Substitution"
|
|
HREF="x2563.htm"><LINK
|
|
REL="NEXT"
|
|
TITLE="Working with the file-system"
|
|
HREF="c2690.htm"></HEAD
|
|
><BODY
|
|
CLASS="SECT1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>GNU/Linux Command-Line Tools Summary</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="x2563.htm"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 6. Directing Input/Output</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="c2690.htm"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="PERFORMING-MORE-THAN-ONE-COMMAND"
|
|
></A
|
|
>Performing more than one command</H1
|
|
><P
|
|
></P
|
|
><DIV
|
|
CLASS="VARIABLELIST"
|
|
><DL
|
|
><DT
|
|
>Executing the second command only if the first is successful<A
|
|
NAME="EXECUTE-COMMAND-2-IF-1-WORKS"
|
|
></A
|
|
></DT
|
|
><DD
|
|
><P
|
|
> </P
|
|
><P
|
|
>To do this you would type:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>command1 && command2</PRE
|
|
><P
|
|
><A
|
|
NAME="AEN2633"
|
|
></A
|
|
>command2<A
|
|
NAME="AEN2635"
|
|
></A
|
|
> will be executed if command1 <A
|
|
NAME="AEN2637"
|
|
></A
|
|
>successfully completes (if command1 fails <A
|
|
NAME="AEN2639"
|
|
></A
|
|
>command2 <A
|
|
NAME="AEN2641"
|
|
></A
|
|
>won't be run). This is called a logical <A
|
|
NAME="AEN2643"
|
|
></A
|
|
>AND.<A
|
|
NAME="AEN2645"
|
|
></A
|
|
></P
|
|
></DD
|
|
><DT
|
|
>Executing the second command only if the first fails<A
|
|
NAME="EXECUTE-COMMAND-2-IF-1-FAILS"
|
|
></A
|
|
></DT
|
|
><DD
|
|
><P
|
|
> </P
|
|
><P
|
|
>To do this you would type:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>command1 || command2</PRE
|
|
><P
|
|
><A
|
|
NAME="AEN2655"
|
|
></A
|
|
>command2 <A
|
|
NAME="AEN2657"
|
|
></A
|
|
>will be executed if command1 <A
|
|
NAME="AEN2659"
|
|
></A
|
|
>does not successfully complete (if command1 <A
|
|
NAME="AEN2661"
|
|
></A
|
|
>is successful <A
|
|
NAME="AEN2663"
|
|
></A
|
|
>command2 won't be run). This is called a logical <A
|
|
NAME="AEN2665"
|
|
></A
|
|
>OR.<A
|
|
NAME="AEN2667"
|
|
></A
|
|
></P
|
|
></DD
|
|
><DT
|
|
>Executing commands sequentially<A
|
|
NAME="EXECUTING-COMMANDS-SEQUENTIALLY"
|
|
></A
|
|
></DT
|
|
><DD
|
|
><P
|
|
> </P
|
|
><P
|
|
>To execute commands sequentially <A
|
|
NAME="AEN2675"
|
|
></A
|
|
>regardless of the success/failure of the previous <A
|
|
NAME="AEN2677"
|
|
></A
|
|
>you simply type:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>command1; command2</PRE
|
|
><P
|
|
><A
|
|
NAME="AEN2681"
|
|
></A
|
|
>command2 <A
|
|
NAME="AEN2683"
|
|
></A
|
|
>will execute once command1 <A
|
|
NAME="AEN2685"
|
|
></A
|
|
>has completed.</P
|
|
><DIV
|
|
CLASS="TIP"
|
|
><BLOCKQUOTE
|
|
CLASS="TIP"
|
|
><P
|
|
><B
|
|
>More than two commands: </B
|
|
>You can continue to use ';' (semicolon) characters to do more and more commands on the one line.</P
|
|
></BLOCKQUOTE
|
|
></DIV
|
|
></DD
|
|
></DL
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="x2563.htm"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="book1.htm"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="c2690.htm"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Command Substitution</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="c2269.htm"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Working with the file-system</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |