Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Linux Shell Scripting – Fundamentals of Bash 4.4

You're reading from   Learn Linux Shell Scripting ‚àö¬¢‚Äö√ᬮ‚Äö√Ñ√∫ Fundamentals of Bash 4.4 A comprehensive guide to automating administrative tasks with the Bash shell

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher Packt
ISBN-13 9781788995597
Length 452 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sebastiaan Tammer Sebastiaan Tammer
Author Profile Icon Sebastiaan Tammer
Sebastiaan Tammer
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Introduction 2. Setting Up Your Local Environment FREE CHAPTER 3. Choosing the Right Tools 4. The Linux Filesystem 5. Understanding the Linux Permissions Scheme 6. File Manipulation 7. Hello World! 8. Variables and User Input 9. Error Checking and Handling 10. Regular Expressions 11. Conditional Testing and Scripting Loops 12. Using Pipes and Redirection in Scripts 13. Functions 14. Scheduling and Logging 15. Parsing Bash Script Arguments with getopts 16. Bash Parameter Substitution and Expansion 17. Tips and Tricks with Cheat Sheet 18. Assessments 19. Other Books You May Enjoy

Advanced if-then-else


This chapter is dedicated to everything to do with conditional testing and scripting loops, which are two concepts that are often intertwined. We have already seen the if-then-else loop in Chapter 9, Error Checking and Handling, which focused on error checking and handling. We'll present a small recap of the things we've described regarding if-then-else, before moving on to advanced concepts.

A recap on if-then-else 

If-then-else logic does almost exactly what the name implies: ifsomething-is-the-case, thendo-something or elsedo-something-else. In practice, this could be ifthe disk is full, thendelete some files or elsereport that the disk space looks great. In a script, this could look something like this:

reader@ubuntu:~/scripts/chapter_09$ cat if-then-else-proper.sh 
#!/bin/bash

#####################################
# Author: Sebastiaan Tammer
# Version: v1.0.0
# Date: 2018-09-30
# Description: Use the if-then-else construct, now properly.
# Usage: ./if-then-else-proper...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image