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

271 lines
4.0 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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 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
><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 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
><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 commands sequentially<A
NAME="EXECUTING-COMMANDS-SEQUENTIALLY"
></A
></DT
><DD
><P
> </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
>