old-www/LDP/Bash-Beginners-Guide/html/chap_07.html

300 lines
3.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Conditional statements</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Bash Guide for Beginners"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Exercises"
HREF="sect_06_05.html"><LINK
REL="NEXT"
TITLE="Introduction to if"
HREF="sect_07_01.html"></HEAD
><BODY
CLASS="chapter"
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"
>Bash Guide for Beginners</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="sect_06_05.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="sect_07_01.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="chap_07"
></A
>Chapter 7. Conditional statements</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
>7.1. <A
HREF="sect_07_01.html"
>Introduction to if</A
></DT
><DD
><DL
><DT
>7.1.1. <A
HREF="sect_07_01.html#sect_07_01_01"
>General</A
></DT
><DT
>7.1.2. <A
HREF="sect_07_01.html#sect_07_01_02"
>Simple applications of if</A
></DT
></DL
></DD
><DT
>7.2. <A
HREF="sect_07_02.html"
>More advanced if usage</A
></DT
><DD
><DL
><DT
>7.2.1. <A
HREF="sect_07_02.html#sect_07_02_01"
>if/then/else constructs</A
></DT
><DT
>7.2.2. <A
HREF="sect_07_02.html#sect_07_02_02"
>if/then/elif/else constructs</A
></DT
><DT
>7.2.3. <A
HREF="sect_07_02.html#sect_07_02_03"
>Nested if statements</A
></DT
><DT
>7.2.4. <A
HREF="sect_07_02.html#sect_07_02_04"
>Boolean operations</A
></DT
><DT
>7.2.5. <A
HREF="sect_07_02.html#sect_07_02_05"
>Using the exit statement and if</A
></DT
></DL
></DD
><DT
>7.3. <A
HREF="sect_07_03.html"
>Using case statements</A
></DT
><DD
><DL
><DT
>7.3.1. <A
HREF="sect_07_03.html#sect_07_03_01"
>Simplified conditions</A
></DT
><DT
>7.3.2. <A
HREF="sect_07_03.html#sect_07_03_02"
>Initscript example</A
></DT
></DL
></DD
><DT
>7.4. <A
HREF="sect_07_04.html"
>Summary</A
></DT
><DT
>7.5. <A
HREF="sect_07_05.html"
>Exercises</A
></DT
></DL
></DIV
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN4515"
></A
><P
></P
><P
>In this chapter we will discuss the use of conditionals in Bash scripts. This includes the following topics:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>The <B
CLASS="command"
>if</B
> statement</P
></LI
><LI
><P
>Using the exit status of a command</P
></LI
><LI
><P
>Comparing and testing input and files</P
></LI
><LI
><P
><B
CLASS="command"
>if/then/else</B
> constructs</P
></LI
><LI
><P
><B
CLASS="command"
>if/then/elif/else</B
> constructs</P
></LI
><LI
><P
>Using and testing the positional parameters</P
></LI
><LI
><P
>Nested <B
CLASS="command"
>if</B
> statements</P
></LI
><LI
><P
>Boolean expressions</P
></LI
><LI
><P
>Using <B
CLASS="command"
>case</B
> statements</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
></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="sect_06_05.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="sect_07_01.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Exercises</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Introduction to if</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>