This is the code repository for The Ultimate Linux Shell Scripting Guide, First Edition, published by Packt.
Donald A. Tevault
Embark on a comprehensive journey through command shells with this hands-on manual. While Bash is a Linux staple, Z shell and PowerShell are rising stars, applicable to Linux, macOS, and Unix. Progress seamlessly through chapters, each building on the last, creating a solid foundation. Learn through a unique approach: concepts, examples, and interactive labs. These labs, nearly a hundred strong, form the core of experiential learning, essential for script creation.
Focusing on Linux commands and their scripting applications, this manual is universally relevant across Linux and select Unix-like systems. It goes beyond theory, offering practical scripts for real-world Linux administration. Scripts are designed for manageability, aiding learning and troubleshooting. The goal is to nurture the ability to craft intelligent, functional shell scripts.
While centered on Bash, this book offers a peek into the future with Z Shell and PowerShell, expanding your skills and adaptability. This book is systematically structured and engaging so that it will guide you to master command shells, equipping you for real-world Linux challenges.
- Grasp the concept of shells and explore their diverse types for varied system interactions
- Master redirection, pipes, and compound commands for efficient shell operations
- Leverage text stream filters within scripts for dynamic data manipulation
- Harness functions and build libraries to create modular and reusable shell scripts
- Explore the basic programming constructs that apply to all programming languages
- Engineer portable shell scripts, ensuring compatibility across diverse platforms beyond Linux
- Getting Started with the Shell
- Interpreting Commands
- Understanding Variables and Pipelines
- Understanding Input/Output Redirection
- Customizing the Environment
- Text Stream Filters – Part 1
- Text Stream Filters – Part 2
- Basic Shell Script Construction
- Filtering Text with grep, sed, and Regular Expressions
- Understanding Functions
- Performing Mathematical Operations
- Automating Scripts with here Documents and expect
- Scripting with ImageMagick
- Using awk–Part 1
- Using awk–Part 2
- Creating User Interfaces with yad, dialog, and xdialog
- Using Shell Script Options with getops
- Shell Scripting for Security Professionals
- Shell Script Portability
- Shell Script Security
- Debugging Shell Scripts
- Introduction to Z Shell Scripting
- Using PowerShell on Linux
Since the book begins with the very basics of Linux and Unix command-line usage, the reader really just needs to be comfortable with the idea of setting up VirtualBox and installing Linux, FreeBSD, and OpenIndiana virtual machines.
VirtualBox is a free download that you can get from here Download VirtualBox (Free).
To run VirtualBox, you’ll need a machine with a CPU that is capable of virtualization. Most modern CPUs have that capability, with the exception of certain Intel Core i3 and Core i5 models. (That’s because they lack the hardware acceleration that’s required for virtualization.) Also, you’ll have to ensure that virtualization is enabled in your computer’s BIOS. For the demos, we’ll be using Fedora, Debian, Ubuntu, FreeBSD, and OpenIndiana virtual machines. Here’s where you can download the installation images:
- Fedora: Get Fedora
- Debian: Get Debian
- Ubuntu: Get Ubuntu
- FreeBSD: Get FreeBSD
- OpenIndiana: Get OpenIndiana
In all cases, you’ll need to create a normal user account that has full sudo privileges. That happens automatically with Ubuntu and OpenIndiana during installation. With Debian and Fedora, that will happen automatically if you omit creating a root user password during installation. For FreeBSD, things are a bit different. That’s because the FreeBSD installer will have you create a password for the root user, and sudo won’t be installed. So, here’s the procedure for installing FreeBSD.
-
Ubuntu & OpenIndiana: Automatically grants sudo privileges during installation.
-
Debian & Fedora: Omit creating a root user password during installation to grant the user full sudo privileges.
-
For FreeBSD:
-
Add yourself to the
wheel
group during FreeBSD installation, like this:
-
When you get to the installer section that has you create your own user account, you’ll see:
Login group is `your_username`. Invite `your_username` into other groups.
Respond by typingwheel
, in order to add yourself to the wheel group. -
After the installation has completed, log into the root user account, using the password that you created during installation.
Install sudo on FreeBSD, like this: -
Install the sudo package by doing:
pkg install sudo
-
Configure
sudo
so that members of the wheel group have full sudo privileges. Begin by entering the command:visudo
-
Scroll down to where you see this line:
# %wheel ALL=(ALL:ALL) ALL
- Remove the
#
and any leading spaces from this line. - Save and exit.
- Remove the
-
Log out from the root user's account, and log back in with your own account. When you need to perform an administrative command, you can now use sudo, as you would on any Linux distro.
Next, you’ll need to install bash
on FreeBSD.
Since bash
doesn’t come installed on FreeBSD by default, you’ll need to install it yourself. Here’s the
procedure.
- Install
bash
with this commandsudo pkg install bash
- Create a symbolic line to the
bash
executable, like this:sudo ln -s /usr/local/bin/bash /bin/bash
Donald A. Tevault but you can call him Donnie - got involved with Linux way back in 2006, and has been working with it ever since. He holds the Linux Professional Institute Level 3-Security certification, and the GIAC Incident Handler certification. Donnie is a professional Linux trainer, and thanks to the magic of the internet, teaches Linux classes literally the world over from the comfort of his living room. He's also a Linux security researcher for an IoT security company.