old-www/LDP/GNU-Linux-Tools-Summary/html/performing-more-than-one-co...

271 lines
4.0 KiB
HTML
Raw Permalink Normal View History

2020-08-23 10:33:19 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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="index.html"><LINK
REL="UP"
TITLE="Directing Input/Output"
HREF="directing-input-ouput.html"><LINK
REL="PREVIOUS"
TITLE="Command Substitution"
HREF="command-substitution.html"><LINK
REL="NEXT"
TITLE="Working with the file-system"
HREF="working-with-the-file-system.html"></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="command-substitution.html"
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="working-with-the-file-system.html"
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
>6.4. Performing more than one command</H1
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Executing<6E>the<68>second<6E>command<6E>only<6C>if<69>the<68>first<73>is<69>successful<A
NAME="EXECUTE-COMMAND-2-IF-1-WORKS"
></A
></DT
><DD
><P
><3E></P
><P
>To do this you would type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>command1 &#38;&#38; command2</PRE
></FONT
></TD
></TR
></TABLE
><P
>command2 will be executed if command1 successfully completes (if command1 fails command2 won't be run). This is called a logical AND.</P
></DD
><DT
>Executing<6E>the<68>second<6E>command<6E>only<6C>if<69>the<68>first<73>fails<A
NAME="EXECUTE-COMMAND-2-IF-1-FAILS"
></A
></DT
><DD
><P
><3E></P
><P
>To do this you would type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>command1 || command2</PRE
></FONT
></TD
></TR
></TABLE
><P
>command2 will be executed if command1 does not successfully complete (if command1 is successful command2 won't be run). This is called a logical OR.</P
></DD
><DT
>Executing<6E>commands<64>sequentially<A
NAME="EXECUTING-COMMANDS-SEQUENTIALLY"
></A
></DT
><DD
><P
><3E></P
><P
>To execute commands sequentially regardless of the success/failure of the previous you simply type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>command1; command2</PRE
></FONT
></TD
></TR
></TABLE
><P
>command2 will execute once command1 has completed.</P
><DIV
CLASS="TIP"
><P
></P
><TABLE
CLASS="TIP"
WIDTH="90%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>More than two commands</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>You can continue to use ';' (semicolon) characters to do more and more commands on the one line.</P
></TD
></TR
></TABLE
></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="command-substitution.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="working-with-the-file-system.html"
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="directing-input-ouput.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Working with the file-system</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>