24.07.2018 Views

Bash-Beginners-Guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />

Table of Contents<br />

Chapter 7. Conditional statements<br />

7.2.4. Boolean operations................................................................................................................88<br />

7.2.5. Using the exit statement and if..............................................................................................89<br />

7.3. Using case statements.....................................................................................................................90<br />

7.3.1. Simplified conditions............................................................................................................90<br />

7.3.2. Initscript example..................................................................................................................92<br />

7.4. Summary.........................................................................................................................................92<br />

7.5. Exercises.........................................................................................................................................93<br />

Chapter 8. Writing interactive scripts............................................................................................................94<br />

8.1. Displaying user messages...............................................................................................................94<br />

8.1.1. Interactive or not?..................................................................................................................94<br />

8.1.2. Using the echo built-in command.........................................................................................94<br />

8.2. Catching user input.........................................................................................................................97<br />

8.2.1. Using the read built-in command..........................................................................................97<br />

8.2.2. Prompting for user input........................................................................................................98<br />

8.2.3. Redirection and file descriptors.............................................................................................99<br />

8.2.4. File input and output............................................................................................................101<br />

8.3. Summary.......................................................................................................................................106<br />

8.4. Exercises.......................................................................................................................................106<br />

Chapter 9. Repetitive tasks............................................................................................................................108<br />

9.1. The for loop...................................................................................................................................108<br />

9.1.1. How does it work?...............................................................................................................108<br />

9.1.2. Examples.............................................................................................................................108<br />

9.2. The while loop..............................................................................................................................109<br />

9.2.1. What is it?............................................................................................................................109<br />

9.2.2. Examples.............................................................................................................................110<br />

9.3. The until loop................................................................................................................................112<br />

9.3.1. What is it?............................................................................................................................112<br />

9.3.2. Example...............................................................................................................................112<br />

9.4. I/O redirection and loops..............................................................................................................113<br />

9.4.1. Input redirection..................................................................................................................113<br />

9.4.2. Output redirection................................................................................................................113<br />

9.5. Break and continue.......................................................................................................................114<br />

9.5.1. The break built-in................................................................................................................114<br />

9.5.2. The continue built-in...........................................................................................................115<br />

9.5.3. Examples.............................................................................................................................116<br />

9.6. Making menus with the select built-in..........................................................................................117<br />

9.6.1. General................................................................................................................................117<br />

9.6.2. Submenus............................................................................................................................118<br />

9.7. The shift built-in...........................................................................................................................118<br />

9.7.1. What does it do?..................................................................................................................118<br />

9.7.2. Examples.............................................................................................................................119<br />

9.8. Summary.......................................................................................................................................120<br />

9.9. Exercises.......................................................................................................................................120<br />

iv

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!