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
Learn Linux Shell Scripting – Fundamentals of Bash 4.4
Learn Linux Shell Scripting – Fundamentals of Bash 4.4

Learn Linux Shell Scripting – Fundamentals of Bash 4.4: A comprehensive guide to automating administrative tasks with the Bash shell

eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learn Linux Shell Scripting – Fundamentals of Bash 4.4

Setting Up Your Local Environment

In the previous chapter, we ventured into some context for the wonderful world of Linux and Bash. Since this is a practical, exercise-driven book, we're going to use this chapter to set up a machine where you can follow along with the examples and perform the exercises at the end of each chapter. This can either be a virtual machine or a physical installation; that is up to you. We will discuss this in the first part of this chapter, before continuing with the installation of VirtualBox and, finally, creating an Ubuntu virtual machine.

The following command will be introduced in this chapter: ssh and exit.

The following topics will be covered in this chapter:

  • Choosing between a virtual machine and a physical installation
  • Setting up VirtualBox
  • Creating an Ubuntu virtual machine

Technical requirements

To complete the exercises in this chapter (and the following chapters), you will need either a PC or laptop with at least 2 GHz of CPU power, 10 GB of hard disk space, and about 1 GB of RAM to spare. Pretty much all hardware created in the last 5 years should suffice.

Choosing between a virtual machine and a physical installation

A virtual machine is an emulation of a physical machine. This means it runs inside a physical machine, as opposed to directly on the hardware. A physical machine has direct access to all hardware, such as the CPU, the RAM, and other devices such as the mouse, the keyboard, and the monitor. It is, however, impossible to share the CPU or the RAM between multiple physical machines. Virtual machines do not directly get access to hardware, but through an emulation layer, which means resources can be shared between multiple virtual machines.

Because we're discussing Bash shell scripting in general, in theory it does not matter what kind of an installation is performed. As long as that installation runs a compatible Linux operating system with Bash 4.4 or later, all exercises should work. There are, however, many advantages...

Setting up VirtualBox

To use virtual machines, we need software called a hypervisor. A hypervisor manages resources between the host machine and the virtual machines, provides access to disks, and has an interface to manage it all. There are two different types of hypervisors: type-1 and type-2. Type-1 hypervisors are the so-called bare-metal hypervisors. These are installed instead of a regular operating system such as Linux, macOS, or Windows, directly on the hardware. These types of hypervisors are used for corporate servers, cloud services, and so on. For this book, we will use a type-2 hypervisor (also called hosted hypervisors): these are installed within another operating system, as a piece of software not much different than, for example, a browser.

There are many type-2 hypervisors. The most popular choices at the time of writing are VirtualBox, VMware workstation player...

Creating an Ubuntu virtual machine

In this book, we're scripting with Bash, which means we do not need a GUI for our Linux installation. We have chosen to use Ubuntu Server 18.04 LTS as the virtual machine operating system, for a number of reasons:

  • Ubuntu is considered a beginner-friendly Linux distribution
  • The 18.04 is a Long-Term Support (LTS) release, which means it will receive updates until April 2023
  • Because an Ubuntu server offers a CLI-only installation, it is easy on system resources and representative of real-life servers

At the time of writing, Ubuntu is maintained by Canonical. You can download the ISO image from https://www.ubuntu.com/download/server. Download the file now, and remember where you save this file, since you'll need it soon.

Should the preceding download link no longer work, you can go to your favorite search engine and search for...

Summary

In this chapter, we have started preparing our local machine for the rest of the book. We now know about the differences between virtual and physical machines, and why we prefer to use a virtual machine for the remainder of this book. We've learned about the two different types of hypervisors. We have installed and configured VirtualBox with a virtual machine, on which we have installed the Ubuntu 18.04 operating system. Finally, we have connected to our running virtual machine using SSH instead of the VirtualBox terminal, which affords better usability and options.

The following command was introduced in this chapter: ssh and exit.

In the next chapter, we will finish setting up our local machine by looking at some different tools we can use that will help us with bash scripting, both on the GUI and on the virtual machine CLI.

...

Questions

  1. What are some of the reasons running a virtual machine would be preferable to a bare-metal installation?
  2. What are some of the downsides of running a virtual machine as opposed to a bare-metal installation?
  3. What is the difference between a type-1 and type-2 hypervisor?
  4. In which two ways can we start a virtual machine on VirtualBox?
  5. What makes an Ubuntu LTS version special?
  6. What should we do if, after the Ubuntu installation, the virtual machine boots to the Ubuntu installation screens again?
  7. What should we do if we accidentally reboot during installation, and we never end up at the Ubuntu installation (but instead see an error)?
  8. Why did we set up NAT forwarding for the virtual machine?

Further reading

Left arrow icon Right arrow icon

Key benefits

  • Get up and running with Linux shell scripting using real-world examples
  • Leverage command-line techniques and methodologies to automate common yet complex administration tasks
  • A practical guide with exposure to scripting constructs and common scripting patterns

Description

Shell scripts allow us to program commands in chains and have the system execute them as a scripted event, just like batch files. This book will start with an overview of Linux and Bash shell scripting, and then quickly deep dive into helping you set up your local environment, before introducing you to tools that are used to write shell scripts. The next set of chapters will focus on helping you understand Linux under the hood and what Bash provides the user. Soon, you will have embarked on your journey along the command line. You will now begin writing actual scripts instead of commands, and will be introduced to practical applications for scripts. The final set of chapters will deep dive into the more advanced topics in shell scripting. These advanced topics will take you from simple scripts to reusable, valuable programs that exist in the real world. The final chapter will leave you with some handy tips and tricks and, as regards the most frequently used commands, a cheat sheet containing the most interesting flags and options will also be provided. After completing this book, you should feel confident about starting your own shell scripting projects, no matter how simple or complex the task previously seemed. We aim to teach you how to script and what to consider, to complement the clear-cut patterns that you can use in your daily scripting challenges.

Who is this book for?

This book targets new and existing Linux system administrators, Windows system administrators or developers who are interested in automating administrative tasks. No prior shell scripting experience is needed but in case you do this book will make a pro quickly. Readers should have a basic understanding of the command line.

What you will learn

  • Understand Linux and Bash basics as well as shell scripting fundamentals
  • Learn to write simple shell scripts that interact with Linux operating system
  • Build, maintain, and deploy scripts in a Linux environment
  • Learn best practices for writing shell scripts
  • Avoid common pitfalls associated with Bash scripting
  • Gain experience and the right toolset to write your own complex shell scripts

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 31, 2018
Length: 452 pages
Edition : 1st
Language : English
ISBN-13 : 9781788990240
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 31, 2018
Length: 452 pages
Edition : 1st
Language : English
ISBN-13 : 9781788990240
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 99.97
Linux Administration Cookbook
€36.99
Learn Linux Shell Scripting – Fundamentals of Bash 4.4
€32.99
Command Line Fundamentals
€29.99
Total 99.97 Stars icon
Banner background image

Table of Contents

19 Chapters
Introduction Chevron down icon Chevron up icon
Setting Up Your Local Environment Chevron down icon Chevron up icon
Choosing the Right Tools Chevron down icon Chevron up icon
The Linux Filesystem Chevron down icon Chevron up icon
Understanding the Linux Permissions Scheme Chevron down icon Chevron up icon
File Manipulation Chevron down icon Chevron up icon
Hello World! Chevron down icon Chevron up icon
Variables and User Input Chevron down icon Chevron up icon
Error Checking and Handling Chevron down icon Chevron up icon
Regular Expressions Chevron down icon Chevron up icon
Conditional Testing and Scripting Loops Chevron down icon Chevron up icon
Using Pipes and Redirection in Scripts Chevron down icon Chevron up icon
Functions Chevron down icon Chevron up icon
Scheduling and Logging Chevron down icon Chevron up icon
Parsing Bash Script Arguments with getopts Chevron down icon Chevron up icon
Bash Parameter Substitution and Expansion Chevron down icon Chevron up icon
Tips and Tricks with Cheat Sheet Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Tim Gourley Jun 18, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is pretty good about getting you up and going, especially if you are not super familiar with using bash on a Linux-based system. It starts you out by getting a virtual machine running with Ubuntu, and takes you through all the fundamentals of using bash from the simplest commands to using regular expressions and advanced shell scripting. It's more than a reference, too; each chapter has lots of questions at the end and further reading if you want to dive even deeper into the topics presented. Even a bash pro will learn something new.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.