0% found this document useful (0 votes)
3 views72 pages

(Ebook) Mastering Linux Shell Scripting, Second Edition by Mokhtar Ebrahim, Andrew Mallett ISBN 9781788990554, 1788990552 Download

The document is about the ebook 'Mastering Linux Shell Scripting, Second Edition' by Mokhtar Ebrahim and Andrew Mallett, which serves as a practical guide to Linux command-line, Bash scripting, and Shell programming. It includes details about the authors, publication information, and various chapters covering topics like creating interactive scripts, conditions, functions, and using Python as an alternative to Bash scripting. Additionally, it provides links for purchasing the ebook and accessing related resources.

Uploaded by

rljuevsiu8024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views72 pages

(Ebook) Mastering Linux Shell Scripting, Second Edition by Mokhtar Ebrahim, Andrew Mallett ISBN 9781788990554, 1788990552 Download

The document is about the ebook 'Mastering Linux Shell Scripting, Second Edition' by Mokhtar Ebrahim and Andrew Mallett, which serves as a practical guide to Linux command-line, Bash scripting, and Shell programming. It includes details about the authors, publication information, and various chapters covering topics like creating interactive scripts, conditions, functions, and using Python as an alternative to Bash scripting. Additionally, it provides links for purchasing the ebook and accessing related resources.

Uploaded by

rljuevsiu8024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

(Ebook) Mastering Linux Shell Scripting, Second

Edition by Mokhtar Ebrahim, Andrew Mallett ISBN


9781788990554, 1788990552 download

https://ebooknice.com/product/mastering-linux-shell-scripting-
second-edition-42970142

Download more ebook instantly today at https://ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) Mastering Linux Shell Scripting, Second Edition by Mokhtar Ebrahim, Andrew
Mallett ISBN 9781788990554, 1788990552

https://ebooknice.com/product/mastering-linux-shell-scripting-second-
edition-42970140

ebooknice.com

(Ebook) Mastering Linux Shell Scripting, Second Edition by Mokhtar Ebrahim, Andrew
Mallett ISBN 9781788990554, 1788990552

https://ebooknice.com/product/mastering-linux-shell-scripting-second-
edition-42970142

ebooknice.com

(Ebook) Mastering Linux Shell Scripting: a practical guide to Linux command-line,


Bash scripting, and Shell programming by Ebrahim, Mokhtar;Mallett, Andrew ISBN
9781788990158, 9781788990554, 1788990153, 1788990552

https://ebooknice.com/product/mastering-linux-shell-scripting-a-practical-guide-
to-linux-command-line-bash-scripting-and-shell-programming-11381866

ebooknice.com

(Ebook) Mastering Linux shell scripting a practical guide to Linux command- line,
Bash scripting, and Shell programming by Mokhtar Ebrahim; Andrew Mallett ISBN
9781788990158, 1788990153

https://ebooknice.com/product/mastering-linux-shell-scripting-a-practical-guide-
to-linux-command-line-bash-scripting-and-shell-programming-11145962

ebooknice.com
(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James ISBN
9781459699816, 9781743365571, 9781925268492, 1459699815, 1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

ebooknice.com

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans Heikne, Sanna
Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

ebooknice.com

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success) by Peterson's
ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-math-1c-and-2c-2002-peterson-s-sat-
ii-success-1722018

ebooknice.com

(Ebook) Linux Shell Scripting Cookbook, Second Edition by Shantanu Tushar, Sarath
Lakshman ISBN 9781782162742, 1782162747

https://ebooknice.com/product/linux-shell-scripting-cookbook-second-
edition-4450624

ebooknice.com

(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study: the United
States, 1919-41 2nd Edition by Benjamin Harrison ISBN 9781398375147, 9781398375048,
1398375144, 1398375047

https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044

ebooknice.com
Mastering Linux Shell Scripting
Second Edition

A practical guide to Linux command-line, Bash scripting, and Shell


programming

Mokhtar Ebrahim
Andrew Mallett
BIRMINGHAM - MUMBAI
Mastering Linux Shell
Scripting Second Edition
Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any
form or by any means, without the prior written permission of the publisher, except in the case of brief
quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or implied.
Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages
caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the
accuracy of this information.

Commissioning Editor: Vijin Boricha


Acquisition Editor: Rohit Rajkumar
Content Development Editor: Ron Mathew
Technical Editor: Prachi Sawant
Copy Editor: Safis Editing
Project Coordinator: Judie Jose
Proofreader: Safis Editing
Indexer: Mariammal Chettiyar
Graphics: Tom Scaria
Production Coordinator: Aparna Bhagat

First published: December 2015


Second edition: April 2018

Production reference: 1180418

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.

ISBN 978-1-78899-055-4

www.packtpub.com
mapt.io

Mapt is an online digital library that gives you full access to over
5,000 books and videos, as well as industry leading tools to help you
plan your personal development and advance your career. For more
information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical
eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content


PacktPub.com
Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to the
eBook version at www.PacktPub.com and as a print book customer, you are
entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical


articles, sign up for a range of free newsletters, and receive
exclusive discounts and offers on Packt books and eBooks.
Contributors
About the authors
Mokhtar Ebrahim started working as a Linux system administrator
in 2010. He is responsible for maintaining, securing, and
troubleshooting Linux servers for multiple clients around the world.
He loves writing shell and Python scripts to automate his work. He
writes technical articles on the Like Geeks website about Linux,
Python, web development, and server administration. He is a father
to a beautiful girl and a husband to a faithful wife.
I would like to thank my wife for helping me with all her efforts to finish this book. Thank you, Doaa, for being
a part of that. Also, I would like to thank everyone at Packt for working with me to make sure the book is
released. Last but not least, I'd like to thank Brian Fox, the author of the bash shell, for creating such an
awesome piece of software; without it, such a book would not exist.

Andrew Mallett is the owner of The Urban Penguin, and he is a


comprehensive provider of professional Linux software development,
training, and services. Having always been a command-line fan, he
feels that so much time can be saved through knowing command-
line shortcuts and scripting. TheUrbanPenguin YouTube channel,
maintained by Andrew, has well over 800 videos to support this, and
he has authored four other Packt titles.
About the reviewer
Sebastiaan Tammer is a Linux enthusiast from The Netherlands.
After attaining his BSc in Information Sciences, he graduated with
MSc in Business Informatics, both from Utrecht University. His
professional career started in Java development before he pivoted
into Linux.

He has worked on number of technologies, such as Puppet, Chef,


Docker, and Kubernetes. He spends a lot of time in and around his
terminal of choice: bash. Whether it is creating complex scripting
solutions or just automating simple tasks, there is hardly anything he
hasn't done with bash!
I would like to thank my girlfriend, Sanne, for all the help and support she has given me throughout the years.
She has had to endure the late nights studying, me fixing stuff (which I had inevitably broken only hours
earlier), and my endless storytelling about all those exciting new technologies. Thanks for the enormous
amount of patience and love, I could not have done it without you!
Packt is searching for authors
like you
If you're interested in becoming an author for Packt, please visit autho
rs.packtpub.com and apply today. We have worked with thousands of

developers and tech professionals, just like you, to help them share
their insight with the global tech community. You can make a
general application, apply for a specific hot topic that we are
recruiting an author for, or submit your own idea.
Table of Contents
Title Page

Copyright and Credits

Mastering Linux Shell Scripting Second Edition

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the authors

About the reviewer

Packt is searching for authors like you


Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

1. The What and Why of Scripting with Bash

Technical requirements

Types of Linux shells

What is bash scripting?

The bash command hierarchy


Command type

Command PATH

Preparing text editors for scripting

Configuring vim

Configuring nano

Configuring gedit

Creating and executing scripts


Hello World!

Executing the script

Checking the exit status

Ensuring a unique name

Hello Dolly!

Running the script with arguments

The importance of correct quotes

Printing the script name

Declaring variables

User-defined variables

Environment variables

Variable scope

Command substitution

Debugging your scripts

Summary

Questions

Further reading

2. Creating Interactive Scripts

Technical requirements

Using echo with options

Basic script using read

Script comments

Enhancing scripts with read prompts


Limiting the number of entered characters

Controlling the visibility of the entered text


Passing options

Passing parameters with options


Read options values

Try to be standard
Enhancing learning with simple scripts

Backing-up with scripts


Connecting to a server

Version 1 – ping


Version 2 – SSH

Version 3 – MySQL/MariaDB


Reading files
Summary
Questions

Further reading
3. Conditions Attached

Technical requirements
Simple decision paths using command-line lists

Verifying user input with lists


Using the test shell built-in

Testing strings
Testing integers

Testing file types


Creating conditional statements using if

Extending if with else


Test command with the if command

Checking strings
Checking files and directories

Checking numbers
Combining tests

More conditions with elif


Creating the backup2.sh using elif

Using case statements


Recipe – building a frontend with grep

Summary
Questions

Further reading
4. Creating Code Snippets

Technical requirements
Abbreviations

Using code snippets


Bringing color to the Terminal

Creating snippets using VS Code


Summary

Questions
Further reading

5. Alternative Syntax
Technical requirement
Recapping the test command
Testing files

Adding logic
Square brackets as not seen before

Providing parameter defaults


Variables
Special parameters

Setting defaults
When in doubt – quote!
Advanced tests using [[
White space

Other advanced features


Pattern matching
Regular expressions
Regular expression script

Arithmetic operations using ((


Simple math
Parameter manipulation
Standard arithmetic tests

Summary
Questions
Further reading
6. Iterating with Loops

Technical requirement
for loops
Advanced for loops
The IFS

Counting directories and files


C-style for loops 
Nested loops
Redirecting loop output

Controlling the loop


while loops and until loops
Reading input from files
Creating operator menus

Summary
Questions
Further reading
7. Creating Building Blocks with Functions

Technical requirements
Introducing functions
Passing parameters to functions

Passing arrays
Variable scope
Returning values from functions
Recursive functions

Using functions in menus


Summary
Questions
Further reading

8. Introducing the Stream Editor


Technical requirements
Using grep to display text
Displaying received data on an interface

Displaying user account data


Listing the number of CPUs in a system
Parsing CSV files
The CSV file

Isolating catalog entries


Understanding the basics of sed
The substitute command
Global replacement

Limiting substitution
Editing the file
Other sed commands
The delete command

The insert and append commands


The change command
The transform command
Multiple sed commands

Summary
Questions
Further reading
9. Automating Apache Virtual Hosts

Technical requirements
Apache name-based Virtual Hosts
Creating the virtual host template
First steps

Isolating lines
sed script files
Automating virtual host creation
Prompting for data during site creation

Summary
Questions
Further reading
10. AWK Fundamentals

Technical requirements
The history behind AWK
Displaying and filtering content from files
AWK variables

User-defined variables
Conditional statements
The if command
while loops

for loops
Formatting output
Further filtering to display users by UID
AWK control files

Built-in functions
Summary
Questions
Further reading

11. Regular Expressions


Technical requirements
Regular expression engines
Defining BRE patterns

Anchor characters
The dot character
The character class
Ranges of characters

Special character classes


The asterisk
Defining ERE patterns
The question mark

The plus sign


Curly braces
The pipe character
Expression grouping

Using grep
Summary

Questions

Further reading
12. Summarizing Logs with AWK

Technical requirements

The HTTPD log file format


Displaying data from web logs

Selecting entries by date


Summarizing 404 errors

Summarizing HTTP access codes

Resources hits
Identify image hotlinking

Displaying the highest ranking IP address

Displaying the browser data


Working with email logs

Summary
Questions

Further reading

13. A Better lastlog with AWK


Technical requirements

Using AWK ranges to exclude data

The lastlog command


Horizontally filtering rows with AWK

Counting matched rows


Conditions based on the number of fields
Manipulating the AWK record separator to report on XML data

Apache Virtual Hosts


XML catalog

Summary

Questions
Further reading

14. Using Python as a Bash Scripting Alternative


Technical requirements

What is Python?

Saying Hello World the Python way


Pythonic arguments

Supplying arguments

Counting arguments
Significant whitespace

Reading user input


Using Python to write to files

String manipulation

Summary
Questions

Further reading

Assessments
Chapter 1

Chapter 2
Chapter 3

Chapter 4

Chapter 5
Chapter 6

Chapter 7

Chapter 8
Chapter 9

Chapter 10

Chapter 11
Chapter 12

Chapter 13
Chapter 14

Other Books You May Enjoy


Leave a review - let other readers know what you think
Preface
First, you'll learn about Linux shells and why we chose the bash
shell. Then, you'll learn how to write a simple bash script and how to
edit your bash script using Linux editors.

Following this, you will learn how to define a variable and the
visibility of a variable. After this, you will learn how to store
command execution output into a variable, which is called command
substitution. Also, you will learn how to debug your code using bash
options and Visual Studio Code. You will learn how to make your
bash script interactive to the user by accepting input from the user
using the read command. Then, you will learn how to read options
and its values if the user passed them to the script. Following this,
you will learn how to write conditional statements such as if
statements and how to use case statements. After this, you will
learn how to create code snippets using vim and Visual Studio Code.
For repetitive tasks, you will see how to write for loops, how to
iterate over simple values, and how to iterate over directory content.
Also, you will learn how to write nested loops. Along with this, you
will write while and until loops. Then, we will move on to functions,
the reusable chunks of code. You will learn how to write functions
and how to use them. After this, you will be introduced to one of the
best tools in Linux, which is Stream Editor. As we are still talking
about text processing, we will introduce AWK, one of the best text
processing tools in Linux that you will ever see.

After this, you will learn how to empower your text processing skills
by writing better regular expressions. Finally, you will be introduced
to Python as an alternative to bash scripting.
Who this book is for
This book targets system administrators and developers who would
like to write a better shell script to automate their work. Some
programming experience is preferable. If you don't have any
background in shell scripting, no problem, the book will discuss
everything from the beginning.
What this book covers
, The What and Why of Scripting with Bash, will introduce
Chapter 1

Linux shells, how to write your first shell script, how to prepare your
editor, how to debug your shell script, and some basic bash
programming, such as declaring variables, variable scope, and
command substitution.

, Creating Interactive Scripts, covers how to read input from


Chapter 2

the user using read command, how to pass options to your script,
how to control the visibility of the entered text, and how to limit the
number of entered characters.

, Conditions Attached, will introduce the


Chapter 3 if statement, the case

statement, and other testing command such as else and elif.

, Creating Code Snippets, covers creating and using code


Chapter 4

snippets using editors, such as vim and Visual Studio Code.

, Alternative Syntax, will discuss advanced testing using


Chapter 5 [[

and how to perform arithmetic operations.

Chapter 6, Iterating with Loops, will teach you how to use for loops,
while loops, and until loops to iterate over simple values and complex

values.

, Creating Building Blocks with Functions, will introduce


Chapter 7

functions and explains how to create a function, list builtin functions,


pass parameters to functions, and writing recursive functions.

, Introducing the Stream Editor, will introduce the basics of


Chapter 8

sed tool to manipulate files, such as adding, replacing deleting, and


transforming text.
, Automating Apache Virtual Hosts, contains a practical
Chapter 9

example of sed and explains how to create virtual hosts


automatically using sed.

, AWK Fundamentals, will discuss AWK and how to filter file


Chapter 10

content using it. Also, we will discuss some AWK programming


basics.

, Regular Expressions, covers regular expressions, their


Chapter 11

engines, and how to use them with sed and AWK to empower your
script.

Chapter 12, Summarizing Logs with AWK, will show how to process the
httpd.conf Apache log file using AWK and extract useful well-formatted

data.

, A Better lastlog with AWK, will show you how to use AWK
Chapter 13

to output beautiful reports using the lastlog command by filtering


and processing the lastlog output.

, Using Python as a Bash Scripting Alternative, will discuss


Chapter 14

Python programming language basics and explains how to write


some Python scripts as a bash script alternative.
To get the most out of this
book
I assume that you have a little programming background. Even if
you don't have a programming background, the book will start from
the beginning.

You should know some Linux basics such as the basic commands
such as ls, cd, and which.
Download the example code
files
You can download the example code files for this book from your
account at www.packtpub.com. If you purchased this book elsewhere, you
can visit www.packtpub.com/support and register to have the files emailed
directly to you.

You can download the code files by following these steps:

1. Log in or register at www.packtpub.com.


2. Select the SUPPORT tab.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box and follow the
onscreen instructions.

Once the file is downloaded, please make sure that you unzip or
extract the folder using the latest version of:

WinRAR/7-Zip for Windows


Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://githu
b.com/PacktPublishing/Mastering-Linux-Shell-Scripting-Second-Edition. In case

there's an update to the code, it will be updated on the existing


GitHub repository.

We also have other code bundles from our rich catalog of books and
videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the
screenshots/diagrams used in this book. You can download it from ht

tps://www.packtpub.com/sites/default/files/downloads/MasteringLinuxShellScriptingSec

ondEdition_ColorImages.pdf .
Conventions used
There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder


names, filenames, file extensions, pathnames, dummy URLs, user
input, and Twitter handles. Here is an example: "Edit your script so
that it reads like the following complete code block
for $HOME/bin/hello2.sh"

A block of code is set as follows:


if [ $file_compression = "L" ] ; then
tar_opt=$tar_l
elif [ $file_compression = "M" ]; then
tar_opt=$tar_m
else
tar_opt=$tar_h
fi

Any command-line input or output is written as follows:


$ type ls
ls is aliased to 'ls --color=auto'

Bold: Indicates a new term, an important word, or words that you


see onscreen. For example, words in menus or dialog boxes appear
in the text like this. Here is an example: "Another very useful feature
is found on the Preferences | Plugins tab"
Warnings or important notes appear like this.

Tips and tricks appear like this.


Get in touch
Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book


title in the subject of your message. If you have questions about any
aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy


of our content, mistakes do happen. If you have found a mistake in
this book, we would be grateful if you would report this to us. Please
visit www.packtpub.com/submit-errata, selecting your book, clicking on the
Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any
form on the Internet, we would be grateful if you would provide us
with the location address or website name. Please contact us at
[email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic


that you have expertise in and you are interested in either writing or
contributing to a book, please visit authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why
not leave a review on the site that you purchased it from? Potential
readers can then see and use your unbiased opinion to make
purchase decisions, we at Packt can understand what you think
about our products, and our authors can see your feedback on their
book. Thank you!

For more information about Packt, please visit packtpub.com .


The What and Why of
Scripting with Bash
Welcome to the what and why of bash scripting. In this chapter, you
will discover the types of shells in Linux and why we chose bash. You
will learn what bash is, how to write your first bash script, and how
to run it. Also, you will see how to configure Linux editors, such as
vim and nano, in order to type your code.

Like in any other scripting language, variables are the basic blocks of
coding. You will learn how to declare variables such as integers,
strings, and arrays. Furthermore, you will learn how to export these
variables and extend their scope outside the running process.

Finally, you will see how to visually debug your code using Visual
Studio Code.

We will cover the following topics in this chapter:

Types of Linux shells


What is bash scripting?
The bash command hierarchy
Preparing text editors for scripting
Creating and executing scripts
Declaring variables
Variable scope
Command substitution
Debugging your scripts
Technical requirements
You'll need a running Linux box. It doesn't matter which distribution
you use, since all Linux distributions are shipped nowadays with the
bash shell.

Download and install Visual Studio Code, which is free from


Microsoft. You can download it from here: https://code.visualstudio.com/.

You can use VS Code as an editor instead of vim and nano; it's up to
you.

We prefer to use VS Code because it has a lot of features such as


code completion, debugging, and many more besides.

Install bashdb, which is a required package for the bash debug plugin.
If you are using a Red Hat-based distribution, you can install it like
this:
$ sudo yum install bashdb

If you are using a Debian-based distribution, you can install it like


this:
$ sudo apt-get install bashdb

Install the plugin for VS Code, called bash debug, from https://marketpl
ace.visualstudio.com/items?itemName=rogalmic.bash-debug. This plugin will be

used to debug bash scripts.

The source code for this chapter can be downloaded here:

https://github.com/PacktPublishing/Mastering-Linux-Shell-Scripting-Second-Edition/tr

ee/master/Chapter01
Types of Linux shells
As you know, Linux consists of some major parts, such as the kernel,
the shell, and the GUI interface (Gnome, KDE, and so on).

The shell translates your commands and sends them to the system.
Most Linux distributions are shipped with many shells.

Every shell has its own features, and some of them are very popular
among developers today. These are some of the popular ones:

Sh shell: This is called the Bourne shell, this was developed at


AT&T labs in the 70s by a guy named Stephen Bourne. This
shell offers many features.
Bash shell: Also called the Bourne again shell, this is very
popular and compatible with sh shell scripts, so you can run
your sh scripts without changing them. We are going to use this
shell in this book.
Ksh shell: Also called the Korn shell, this is compatible with sh
and bash. Ksh offers some enhancements over the Bourne shell.
Csh and tcsh: Linux was built using the C language and that
drove developers at Berkeley University to develop a C-style
shell in which the syntax is similar to the C language. Tcsh adds
some minor enhancements to csh.

Now we know the types of shells and we know that we are going to
use bash, so what is bash scripting?
What is bash scripting?
The basic idea of bash scripting is to execute multiple commands to
automate a specific job.

As you might know, you can run multiple commands from the shell
by separating them with semi colons (;):
ls ; pwd

The previous line is a mini bash script.

The first command runs, followed by the result of the second


command.

Every keyword you type in bash scripting is actually a Linux binary


(program), even the if statement, or else or while loops. All are Linux
executables.

You can say that the shell is the glue that binds these commands
together.
The bash command hierarchy
When working on the bash shell and when you are sitting
comfortably at your prompt eagerly waiting to type a command, you
will most likely feel that it is a simple matter of typing and hitting the
Enter key. You should know better than to think this, as things are
never quite as simple as we imagine.
Command type
For example, if we type and enter ls to list files, it is reasonable to
think that we were running the command. It is possible, but we
often will be running an alias. Aliases exist in memory as a shortcut
to commands or commands with options; these aliases are used
before we even check for the file. Bash's built-in type command can
come to our aid here. The type command will display the type of
command for a given word entered at the command line. The types
of command are listed as follows:

Alias
Function
Shell built-in
Keyword
File

This list is also representative of the order in which they are


searched. As we can see, it is not until the very end where we
search for the executable file ls.

The following command demonstrates the simple use type:


$ type ls
ls is aliased to 'ls --color=auto'

We can extend this further to display all the matches for the given
command:
$ type -a ls
ls is aliased to 'ls --color=auto'
ls is /bin/ls

If we need to just type in the output, we can use the -t option. This
is useful when we need to test the command type from within a
script and only need the type to be returned. This excludes any
superfluous information, and thus makes it easier for us humans to
read. Consider the following command and output:
$ type -t ls
alias

The output is clear and simple, and is just what a computer or script
requires.

The built-in type can also be used to identify shell keywords such as
if, and case. The following command shows type being used against

multiple arguments and types:


$ type ls quote pwd do id

The output of the command is shown in the following screenshot:

You can also see that the function definition is printed when we
stumble across a function when using type.
Command PATH
Linux will check for executables in the PATH environment only when
the full or relative path to the program is supplied. In general, the
current directory is not searched unless it is in the PATH. It is possible
to include our current directory within the PATH by adding the
directory to the PATH variable. This is shown in the following
command example:
$ export PATH=$PATH:.

This appends the current directory to the value of the PATH variable;
each item in the PATH is separated using a colon. Now your PATH has
been updated to include the current working directory and, each
time you change directories, the scripts can be executed easily. In
general, organizing scripts into a structured directory hierarchy is
probably a great idea. Consider creating a subdirectory called bin
within your home directory and add the scripts into that folder.
Adding $HOME/bin to your PATH variable will enable you to find the scripts
by name and without the file path.

The following command-line list will only create the directory, if it


does not already exist:
$ test -d $HOME/bin || mkdir $HOME/bin

Although the preceding command-line list is not strictly necessary, it


does show that scripting in bash is not limited to the actual script,
and we can use conditional statements and other syntax directly at
the command line. From our viewpoint, we know that the preceding
command will work whether you have the bin directory or not. The
use of the $HOME variable ensures that the command will work without
considering your current filesystem context.
As we work through the book, we will add scripts into the $HOME/bin
directory so that they can be executed regardless of our working
directory.
Preparing text editors for
scripting
Throughout the book, we will be working on Linux Mint, and this will
include the creation and editing of the scripts. You, of course, can
choose the way you wish to edit your scripts and may prefer to
make use of a graphical editor, so we will show some settings in
gedit. We will make one excursion into a Red Hat system to show
screenshots of gedit in this chapter.

Also, we will use Visual Studio Code as a modern GUI editor to edit
and debug our scripts.

To help make the command-line editor easier to use, we can enable


options and we can persist with these options through hidden
configuration files. Gedit and other GUI editors, and their menus, will
provide similar functionality.
Configuring vim
Editing the command line is often a must and is part of a developer's
everyday life. Setting up common options that make life easier in the
editor give us the reliability and consistency we need, a little like
scripting itself. We will set some useful options in the vi or vim editor
file, $HOME/.vimrc.

The options we set are detailed in the following list:

set showmode: Ensures we see when we are in insert mode


set nohlsearch: Does not highlight the words that we have

searched for
set autoindent: We indent our code often; this allows us to return

to the last indent level rather than the start of a new line on
each line break
set tabstop=4: Sets a tab to be four spaces

set expandtab: Converts tabs to spaces, which is useful when the

file moves to other systems


syntax on: Note that this does not use the set command and is

used to turn on syntax highlighting

When these options are set, the $HOME/.vimrc file should look similar to
this:
set showmode
set nohlsearch
set autoindent
set tabstop=4
set expandtab
syntax on
Configuring nano
The nano text editor is increasing in importance and it is the default
editor in many systems. Personally, I don't like the navigation or the
lack of navigation features that it has. It can be customized in the
same way as vim. This time, we will edit the $HOME/.nanorc file. Your
edited file should look something like the following:
set autoindent
set tabsize 4
include /usr/share/nano/sh.nanorc

The last line enables syntax highlighting for shell scripts.


Configuring gedit
Graphical editors, such as gedit, can be configured using the
preferences menu, and are pretty straightforward.

Enabling tab spacing to be set to 4 spaces and expanding tabs to


spaces can be done using the Preferences | Editor tab, as shown in
the following screenshot:
You can download the example code files from your account at http://www.packtpub.com for all
the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can
visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Another very useful feature is found on the Preferences | Plugins


tab. Here, we can enable the Snippets plugin, which can be used to
insert code samples. This is shown in the following screenshot:
Exploring the Variety of Random
Documents with Different Content
They went through all the rooms while she sat watching, Meredith
lounging beside her in a chair, occasionally getting up to take a turn about
the hall. If the policeman had been a man of any penetration, he would have
seen that his investigations in these rooms were of no interest to the
watchers, but that their excitement grew fierce every time he emerged into
the hall.
Meredith felt the fire in his veins burn stronger as they came back and
forward. It was with difficulty he could restrain his agitation. Mrs.
Harwood’s chair had been pushed aside, leaving the access open to that
mysterious door. She sat with her head turned away a little, her hands
clasped together, an image of suspense and painful anxiety, listening for the
men’s steps as they drew nearer. Gussy had followed the rest of the party,
though it was against all her principles to yield to this excitement and make
a show, as she said, of her feelings. She was vexed especially to see her
mother “give way.”
“Let me put you back into the drawing-room, mamma. What is the use
of staying here? Dolff has gone out, evidently. It is very silly of him, but
still he has done so. It will do him no good for you to catch cold here.
Charley, do tell her to come in. As for you, you will throw yourself back a
week at least. Oh, for goodness’ sake, do not make everything worse by
staying here!”
Mrs. Harwood made no reply. She shook her head with speechless
impatience, and turned her face away. She was beyond all considerations
but one, and she could not bear any interruptions, a voice, a sound, which
kept her strained ears from the knowledge of the men’s movements, and
where they were. Gussy’s whisper continued to Meredith was torture to her.
She raised her hand with an imperative gesture to have silence, silence! her
heart beating in her ears like a sledgehammer rising and falling was surely
enough, without having any whispering and foolish, vain, ineffectual words.
“There’s nothing now but this door,” said the policeman, coming out
somewhat crestfallen. “He’s nowhere else, that’s clear. If he ain’t here he’s
given us the slip—for the moment. Hallo! it’s locked, this one is! I’ll thank
you, sir, to get me the key.”
“I have always understood,” said Meredith, blandly, “that the door was
built up, or fastened up. It has never been used since I have known the
house.”
“I told you so,” said Julia, “if you had listened to me. It isn’t a door at
all, and leads to nowhere. It was once the door of the wing,” she continued,
with the liking of a child for giving information, “but it has never once been
opened since ever I was born.”
“The wing! that’s them empty rooms as we see from the garden—the
very place for a man to hide. Tell you what, sir, I can’t bear to upset the lady
—but we must break in if we can’t get in quietly. You might try if you
couldn’t get us the key, and take the ladies away—anyhow, get the old lady
to go away—whatever happens, she’d better not be here.”
Mrs. Harwood spoke quickly, in a hoarse and broken voice.
“There is no key,” she said.
“I give you five minutes to think of it, lady,” said the man; “otherwise
we must break in the door.”
There was a dreadful silence—a silence which no one dared to break.
“I am telling you the truth; you cannot open it, it has always been shut
up. There is no key.”
CHAPTER XLI.
The policeman’s epigrammatic assertion that it was difficult for a known
man to struggle with the police, is still more true when it is only a door
which stands before a couple of men excited and exasperated by failure and
a probable discovery. The door was a strong door, it was partially plated
with iron, and its lock was cunningly devised, but after a while it began to
give way.
Meredith, altogether absorbed in this new turn of affairs, and carried
away by the prospect which it opened to him as well as to its assailants,
seemed to the bystanders to have altogether gone over to the enemy. He
stood by them, encouraging them in a low tone, suggesting how to strike,
examining into the weak points with the keenest critical eye; in fact, in the
excitement of the moment, forgetting all his precautions and pretence of
indifference, and throwing himself on the side of the assailants. He had, it is
true, the safe ground to fall back upon that, as he had always been assured
there was nothing there, he could do no possible harm in helping to prove
that fact to the men who would not be convinced in any other way.
Mrs. Harwood sat with her face to the door, her arms crossed upon her
breast, her whole frame swaying and moving with the strokes that rained
upon it. When a crash came she shivered and shrank into herself as if the
blow had struck her—a low moan came involuntarily to her lips. Gussy,
who had abandoned Meredith after trying in vain to restrain him, came and
stood by her mother’s chair, with a hand upon her shoulder.
“Oh, mamma, for God’s sake,” said Gussy, in her ear, “don’t! Don’t let
them see you mind it so.”
The mother half turned to her a face which was livid in its terror. Her
eyes, so clear usually, had lost their color even, and seemed to float in a sort
of liquefication, the iris disappearing into the watery black globe—her
mouth was open. She uttered a murmur of inarticulate passion, and made as
though she would have struck the soothing hand. But the men at this
exciting work took no notice of Mrs. Harwood. The officer of the law was
more fit to break down a resisting door than to draw subtle deductions from
the looks of the besieged family. The practical matter was within his sphere.
He only looked round with an exclamation of triumph when the door at last
burst from its holdings, and the dark passage gaped open before them with
its curtains drawn back.
“There!” he shouted, turning round for a moment, “there’s your door that
never was used,” and would have dashed in had not his attendant held him
back.
“I say,” said the man who had hitherto followed him like a shadow, “how
do ye know that he hasn’t got a revolver up there?”
The detective fell back for a moment.
“We’ve got to risk it,” he said, with the professional stoicism of a man
bound to meet danger at any time. He was not of much use in scenting out a
mystery, but he could face a possible revolver with the stolid courage of his
class. He made a pause, however, and added, with a rare effort of reflection,
“And this one’s new to it; he’s not up to their dodges——” They were the
criminal class with which a straightforward policeman is accustomed to
deal.
Meredith followed with an excitement which made him forget
everything, even the group of women bewildered in the hall. He knew his
way, though he dared not show that he did. He followed the burly figure,
and the smaller ill-trained one of the attendant informer and witness, as they
wound themselves up in the curtains and came to a pause opposite every
obstacle. The passage was perfectly dark, but the inner doors were not
closed, notwithstanding the sounds of assault which those within must have
heard. It turned out that the only individual within who had his wits about
him had been too closely occupied to be able to look to those means of
defence.
For a moment the group of the ladies below hung together in bewildered
horror. Then Julia launched herself after the men into the dark passage,
drawn by inextinguishable curiosity and the excitement of a child in sight of
the unknown. Mrs. Harwood had covered her face with her hands, and lay
back in her chair, fallen upon herself like a fallen house, lying, so to speak,
in ruins. Gussy, with her arm round her mother’s shoulders, whispered, with
tears and a little gasping, frightened crying, some words that were intended
to be consolatory in her inattentive ears.
“It is nothing wrong,” Gussy said; “it is nothing wrong. It was to save
him. It is nothing wrong.”
But by-and-bye the strong attraction of that open way along which the
unseen party were stumbling seized upon her also. And her patient, who had
to be taken care of—who was throwing himself back! Gussy cast a piteous
glance upon her mother, lying there with her face upon her hands, paying no
attention, whatever comfort might be poured into her ear, and presently
impatience got the better of her sympathy, and she too followed in the train.
She knew the secret of the wing. She was the only other in the house,
except Mrs. Harwood, to whom that secret was known. But in how innocent
and simple a way! She was troubled, but she had no sense of guilt; and
Gussy said to herself that it was her duty to go and explain, to make it
known to the others how simple it all was, when the fascination became too
much for her to resist, and, with one glance at her mother, she too stole
away. As for Dolff, he had disappeared from their minds, and the incredible
suspicion attached to him, as if he had never been born. From the moment
that the search began it had been to Mrs. Harwood a search for her secret,
and nothing more.
Janet had been all this time hanging about unseen. She could not rest,
she who knew so much more than any one else in the house—both the
mystery of the wing and the miserable story of Dolff and his guilt, both of
them—as nobody else did: neither Mrs. Harwood, whose thoughts were
concentrated upon one, nor Meredith, who had discovered or divined the
other, but did not know as Janet did, who knew everything, what had been
the cause of Dolff’s terrible folly, and what its results, and even when and
how he had disappeared. She had been hanging about now in one room,
now in another, terrified to show herself, incapable of concealing herself,
her very terror of being mixed up in it yielding to the fellow-felling of a
general misery in which she had but her share, and that not so great a share
as the others.
When she saw that the mother of the house, who was the most to be
pitied of all in this dreadful emergency, was left there forlorn and alone,
lying helpless, unable to go after the others, to confront the catastrophe, at
least, as her children could, Janet’s heart was touched. She stole down the
stairs where she had been watching, looking down upon them all, and came
to Mrs. Harwood’s side. It was not for her to console or comfort. Janet was
aware that she had been more or less the cause of all the trouble. She had
found out the family secret, without in the least understanding it, and this
was no blame of hers; but she had betrayed it to one who did understand it,
and who might, for all she knew, use his knowledge unmercifully, being, as
she knew him to be, a man with very little truth or inclination to spare
another. And she had been, without any doubt, the cause of Dolff’s
misfortune in every way. She had taken him into her toils innocently
enough, with no more guiltiness than that of any other girl who had let a
foolish young man fall in love with her, and then had driven him mad by
her falsehood, and led him into crime—almost to the crime of murder. All
this was in Janet’s mind as she stole down the stairs to his mother’s side.
She had plenty of excuse for herself had any one accused her, but in her
heart she was impartial, and knew very well how much she was to blame.
Her heart beat loudly in consonance with the sounds of that exploring party
in the dark passage, going to find out—how much more than they sought!
She understood it all better than anyone. Meredith’s keen satisfaction in
unveiling the mystery, and the stupid astonishment of the strangers, who
had no suspicion, and Gussy——but what Gussy would feel was the one
thing that Janet did not divine, for she was unaware how much or how little
Gussy knew.
She stood by the chair in which Mrs. Harwood lay, all sunken upon
herself like a fallen tower, her face hidden, her shoulders drawn together,
sinking to her knees. Janet dared not say anything. She put her hand upon
the arm of the chair, not even upon the unhappy lady’s arm, which she felt
that she dared not touch—and stood by her. It was all that any one could do.
The two were left there like wrecks on the shore, from, which everything
had ebbed away, even the tumult and the storm which had been raging
round. The sounds went on getting fainter, the voices dropped, the footsteps
seemed to mount and then grow still, stumbling at first a little, gradually
dying out. Mrs. Harwood did not move, nor did Janet, standing by her,
scarcely breathing. Were they both following, in imagination, the darkling
way which both knew, or had the mother, at last, fallen into a blind
insensibility, hearing and knowing no more?
This imagination was, however, suddenly put an end to by a moaning
from the chair.
“I can’t bear this any longer; I can’t bear this!” said Mrs, Harwood. “Oh,
my God! my God! Have they got there?” Then she cried, loudly, “I can’t
bear it! I can’t bear it!” and with a sudden wrench, as if she were tearing
herself like a limb from its socket, the disabled woman rose.
Janet, terrified, gave a cry of dismay as, stumbling and tottering, she
flung herself out of the chair. Whether Mrs. Harwood had been aware of her
presence before this she could not tell; but, at all events, now she was
beyond all sentiment of displeasure or reproof. She put out her shaking
hand and grasped at Janet’s arm as if it had been a post. The girl’s slight
figure swayed and almost gave way at the sudden weight flung upon it; but
the burden steadied her after the first moment’s uncertainty. Mrs.
Harwood’s face had collapsed with the extreme anguish of the crisis past;
her features seemed blurred, like the half-liquid, vaguely floating eyes,
which did not seem to see anything. She made a heavy, uncertain step
forward, carrying her prop with her by mere momentum of weight and
weakness.
“Come,” she said, hoarsely, “come!”

Janet never knew how these dark passages were got through. She was
herself enfolded, carried away in the burden of the helpless woman who
leaned upon her guidance for every step. Their progress was wildly devious
and uneven, every step being a sort of falling forward, which nevertheless
carried them on with spasmodic rapidity, though terrible effort. The voices
and steps in front of them grew audible again, but before they reached the
last door, which stood open with curtains drawn aside, disclosing a warm
blaze of light, there arose a sudden tumult, a roar as of some wild creature,
with answering cries of panic and dismay. The opened doorway suddenly
darkened with a crowd of retreating figures, and Julia darted out from the
midst and came blindly flying upon the tottering group that was struggling
forward.
“Go back, go back!” cried Julia, “whoever you are. There’s a madman
there!” and then she gave a shriek as wild as the sounds that came from the
room, “Oh,” cried the girl, her shrill voice dominating even that riot, “it’s
mamma! My mother’s here!”
CHAPTER XLII.
Next moment they had surged as on the top of a wave to the room
within. Nothing could be more strange than the scene presented there. The
room was curtained all round with red, hung above a man’s height with
ruddy thick folds, upon which the firelight threw a still warmer flicker. A
shaded lamp filled it with softened light, and from above, from what
seemed a large skylight, a white stream of moonlight fell in, making a
curious disturbing effect in the warm artificial light. These accessories,
however, though they told afterwards, were as nothing to the sight that burst
upon the eyes of the new-comers. In the centre of the room stood a tall old
man, with a long pallid face, straggling white hair, and a white beard. His
face was distorted with excitement, his voice bellowing forth a succession
of cries, or rather roars, like the roars of a wild animal. His loose lips gave
forth these utterances with flying foam and a sort of mechanical rapidity:
“I know what you’ve come for? I can pay up! I can pay up! I’ve plenty
of money, and I can pay up! But I won’t be taken, not if it costs me my
life!”
These were the words that finally emancipated themselves from the
stammering utterance and became clear.
Vicars stood behind this wild figure holding both his arms, but it was
only by glimpses that the smaller man was visible holding the other as in a
vise.
“Come, sir, come, sir, no more of this; they’ll take you for a fool,” he
said.
And then this King Lear resumed. The foam flew from his lips; his great
voice came out in its wild bellowing, the very voice which Janet had heard
so often. It had seemed to her to utter but an inarticulate cry, but this, it
would seem, was what it had been saying all the time—words in which
there was some meaning—though what that meaning was, or whether the
speaker himself understood it, who would say?
The policeman and his attendant had edged towards the doorway, and
stood there huddled upon one another. The leader of the search had been
willing to face a revolver, but the madman was a thing for which he was not
prepared. He stood against the doorway ready to retreat still further in case
there should be any further advance. Meredith and Gussy had passed into
the room, and stood together, she very anxious, he very eager, at the side,
where those wild eyes had not caught them. Behind was Dolff very pale,
standing half concealed by the group formed by the madman and his
attendant, raising his head to look over them to the two in the doorway who
had come to look for him, and had received so unexpected a check.
Mrs. Harwood stumbled into the midst of this strange scene with her
tottering uncertain stride, driving Janet with her. She put up her hand to
hold back the dreadful insane figure. She was at one of the moments in life
when one is afraid of nothing, shrinks from nothing.
“Take him back to his seat, Vicars,” she said, “take him back.
Adolphus!” The tottering, helpless woman stood up straight, and put her
hand upon the madman’s breast. The eyes that had been blind with misery
changed and dissolved as if to dew in their orbits, consolidated again,
opened blue and strong like a relighted flame. She fixed them upon the
staring red eyes of the maniac. “Adolphus, go back, be silent, calm yourself.
There is no need for you to say anything. I am here to take care of you. Let
Vicars put you back in your chair.”
“I will not be taken,” he said, “I will not be taken! I can pay up. I have
got money, plenty of money. I will pay up!”
“Vicars,” cried Mrs. Harwood, imperiously, “put him back in his chair.”
She held her hand on his breast, and fixed her eyes upon his, pushing
him softly back. The roarings grew fainter, fell into a kind of whimpering
cry.
“I’ll pay it all—I have plenty of money. Don’t let them take me away—
I’ll pay everything up!”
“Go back and rest in your chair, Adolphus. Put him in his chair.”
The astonished spectators all stood looking on while the old servant and
this woman, whom force of necessity had moved from her own
helplessness, subdued the maniac. Vicars had partially lost his head, he had
lost control of his patient, but this unlooked-for help restored him to
himself. Between them they drew and guided the patient back to the chair,
which was fitted with some mechanical appliances, and held him fast. Mrs.
Harwood seemed to forget her weakness entirely; she tottered no longer, but
moved with a free step. She turned round upon the frightened policeman at
the door.
“Now go,” she said, “you have done your worst; whatever you want, go;
you can get no further satisfaction here.”
The intruder breathed more freely when he saw the madman sink into
quietude. He said, with a voice that quivered slightly.
“I am very willing to go: but that young gentleman has to go along with
me!”
“Come on,” cried the other man, whose teeth were chattering in his head.
“Come on; we’ve got nothing to do here.”
“I’m going: when that young gentleman makes up his mind to come with
me.”
“What young gentleman? Why, bless you, that ain’t the young
gentleman!” said the man, who had struggled out into the passage, and was
now only kept from running by the other’s strong retaining grasp.
It was not wonderful that the policeman was indignant. He let his friend
go with an oath, and with a sudden push which precipitated him into the
outer room.
“You d——d fool! to have led me such a dance; and as much as our lives
are worth, and come to nothing at the end.”
The man fell backward, but got up again in a moment and took to his
heels, with the noise as of a runaway horse in the dark passage. The
policeman, reassured to see that the madman was secured, had the courage
to linger a moment. He turned to Meredith with a defiant look.
“It has come to nothing, sir, and I ask your pardon that I’ve been led into
giving you this trouble by an ass. But I make bold to ask is this house
licensed? and what right has anyone got to keep a dangerous madman in it
without inspection, or any eye over ’im? I’ll have to report it to my
superior.”
“Report it to the—devil, and be off with you,” Meredith said.
The party stood round, staring into each other’s faces, when the strangers
thus withdrew. The madman struggled against the fastenings that secured
him.
“Julia,” he said, “don’t let them take me!” He tried to get hold of her
with his hands, feeling for her as if he did not see, and began to cry feebly,
in a childish, broken voice, “Don’t let them take me! I have got enough to
pay everybody. I kept it for you and the children. It was for you and the
children; but I’ll pay up, I’ll pay everybody; only don’t let them take me,
don’t let them take me!” he whimpered, tears—piteous, childish tears—
suffusing the venerable face.
“Oh,” cried Gussy, “don’t let him cry; for God’s sake don’t let him cry! I
cannot bear it—I cannot bear it—it is too much.”
“I’ll never complain any more,” said the patient; “I’m very comfortable,
I don’t want for anything. You shall pay them all up yourself if you don’t
believe me. I’ll give you the money—only don’t let them send me away!
I’ve got it all safe here,” he said. “Stop a moment, I’ll give it you: and all
these ladies and gentlemen can prove it, that I gave it you to pay up.” He
struggled to get his arms free, trying to reach his breast-pocket with one
hand. “Vicars, get it out, and give it to your mistress. The money—the
money, you know, to pay everybody up. Only,” he cried, putting the piteous
hands together which were held fast and could do so little, “don’t, Julia—
don’t let them take me away!”
“Oh, mamma,” cried Gussy, “I can’t bear it—I can’t bear it.”
She fell on her knees and covered her face.
“Who is he?” said Dolff. They had all of them, and even Dolff himself,
forgotten what was the cause of this revelation. The young man came
forward, very pale. “I know nothing about this,” he said, looking round;
“nothing. I hope everybody will believe me. I want to know who he is!”
No one said a word, they all stood round, struck silent, not knowing
what to think. Mrs. Harwood stood with her hand upon the table, supporting
herself, asking no other support. She was perfectly pale, but her
countenance had recovered its features and expression. She did not even
look at her children—one on her knees, one standing up confronting her,
demanding to know the truth. To neither of them did she give a word or
look. Her eyes were fixed upon the man who was thus utterly in her hands.
Vicars extracted an old, large pocket-book from the pocket of the patient,
and handed it to her, not without a sort of smile—half-mocking—on his
face. She took it, glancing at it with a certain disdain, as if the trick, often
employed but no longer necessary, had disgusted her, and flung it on the
table.
“There are in this book,” she said, “old scraps of paper of no value. This
is what I am to pay his debts with. He has given it to me twenty times
before. I get tired in the end of playing the old game over and over.”
“Mother who is he?” cried Dolff. “You have had him in your house, in
secret, never seeing the light of day, and I, your son, never knew. Who is
he?”
Mrs. Harwood made no reply.
It was a question to which no one there could give any answer, except
perhaps Gussy—on her knees, with her hands covering her face—who did
not look up or give any attention to what was going on. Meredith alone
seemed to have some clear idea in his mind: his face shone with aroused
interest and eagerness, like a man on the very trace of knowledge of the
utmost importance to him. A rapid process of thought was going on in his
mind, his intelligence was leaping from point to point.
“You will perhaps be surprised,” he said, “to hear that I have known this
for some time.”
“You!” Mrs. Harwood half turned to him, a gleam as of fire passing over
her face. “You!”
“Yes, I, who have several interests involved. I had just received
information on the subject when that young fool, thinking heaven knows
what other folly, knocked me down, taking me unawares, and nearly killed
me. Oh, yes, it is perfectly true it was Dolff who did it. You start as if I were
likely to make any fuss on that subject. Is it true that he had the money to
pay everybody?—that is what I want to know.”
“Charley, Charley, do you mean to say that Dolff——”
“Oh, I mean nothing about Dolff,” he said, impatiently: “answer me,
Mrs. Harwood.”
“I can’t answer for nothing, Mrs. Harwood,” cried Vicars, “if you keep a
lot of folks round him. He is working himself up into a fury again.”
The madman was twisting in his chair, fighting against the mechanical
bonds that secured him. He was looking towards the pocket-book which lay
on the table.
“She has got my money, and she throws it down for anybody to pick
up,” he cried. “My money! there’s money there to pay everything! Why
don’t you pay those people and let ’em go—pay them, pay them and let
them go! or else give me back my money!” he cried, wildly straining
forward, with his white hair falling back, his reddened eyes blazing,
struggling against his bonds. Mrs. Harwood took up the pocket-book,
weighing it, with a sort of forced laugh, in her hand.
“You think there may be a fortune here—enough to pay? And he thinks
so. Give it to him, Vicars. We’ve tried to keep it all quiet, but it seems we
have failed. You may leave the door open now—you may do as you please.
It can’t matter any longer. I have thought of the credit of the family, and of
many things that nobody else thinks of. And of his comfort—nobody will
say I have not thought of his comfort. Look round you: there is everything,
everything we could think of. But it is all of no use now.”
The old man had caught the pocket-book from Vicars’ hands with a
pitiful demonstration of joy. He made a pretence of examining its contents,
eagerly turning them over as if to make sure that nothing was lost, kissing
the covers in enthusiasm of delight. He made an attempt with his confined
arms to return it to his pocket, but, failing in that, kept it embraced in both
his hands, from time to time kissing it with extravagant satisfaction.
“As long as I have got this they can do nothing to me,” he said.
While this pantomime was going on, and while still Mrs. Harwood was
speaking, a little movement and rustle in the group caught everybody’s
attention as if it had been a new fact: but it was only Janet stealing away
behind the others who had a right there which she did not possess. She had
been watching her moment. She herself, who had nothing to do with it, had
received her share of discomfiture too. Her heart was sinking with
humiliation and shame. What had she to do with the mysteries of the
Harwoods, the things they might have to conceal? What was she to them
but a stranger of no account, never thought of, dragged into the midst of
their troubles when it pleased them, thrown off again when they chose?
Nobody would have said that Janet had any share in this crisis, and yet it
was she who had received the sharpest arrow of all; or so, at least, she
thought. She slipped behind Julia, who was bigger and more prominent than
she, and stole through the bewildering stairs and passages. How well she
seemed to know the way, as if it had been familiar to her for years! And it
was she who had given the information—she who had been the cause of
everything, drawn here and drawn there into affairs alike alien to her, with
which she had nothing to do. They were all moved by her departure; not
morally, indeed, but by the mere stir it caused.
Gussy rose from her knees, showing a countenance as pale as death and
still glistening with tears. She said,
“Mamma, shall we go away? Whatever there may be to be said or
explained, it ought not to be done here.” She went up to the old man in the
chair, who was still embracing his pocket-book, and kissed him on the
forehead. “If any wrong has been done to you, I don’t know of it,” she said;
“I thought it was nothing but good.”
“No wrong has been done to him—none—none,” cried Mrs. Harwood,
suddenly dropping from her self-command and strength. “Children, you
may not believe me, since I’ve kept it secret from you. There has been no
wrong to him—none—none. If there has been wrong, it has not been to
him. Oh, you may believe me, at least, for I have never told you a lie.
Everything has been done for him. Look round you—look round you and
you will see.”
“Who is he?” said Dolff, obstinate and pale, standing behind the chair.
“You have no thought for me,” said the mother. “You see me standing
here, come here to defend you all, in desperation for you, and you never ask
how I am to get back, whether it will kill me—— No, no, Janet has gone,
who supported me, who was a stranger, and asked no questions, but only
helped a poor woman half mad with trouble and distress. Ah!” she said, “he
could go mad and get free—he who was the cause of it all: but I have had to
keep my sanity and my courage and bear it all, and look as if nothing was
the matter, for fifteen years. For whom? Was it for me? It would have been
better for me to have died and been done with it all. For you, children, to
give you a happy life, to do away with all disgrace, to give you every
advantage. Yes, I’ll take your arm, Ju: you have not been a good child, but
you know no better. Get me to my chair before I drop down; get me to my
chair——” She paused a moment, and looked round with a hard laugh. “For
I am very heavy,” she said, “and I would have to be carried, and who would
do it I don’t know. Ju, make haste, before my strength is all gone. Get me to
my chair.”
CHAPTER XLIII.
Gussy was the last to leave of that strange procession, of whom no one
spoke to the other. She closed the door after her, and the curtains, and
followed the erect figure of Dolff, drawn up as it never had been in his life
before, and walking stiffly, as if carrying a new weight and occupying a
position unknown. They all came into the hall, defiling solemnly one after
the other, to find Mrs. Harwood deposited in her chair and awaiting them,
almost as if the whole events of the evening had been a dream and she had
never left that spot. It was with a strange embarrassment, however, that they
looked at each other in the pale, clear light as they emerged from the
doorway, almost like making new acquaintance, as if they had never seen
each other before. Nobody certainly had seen Dolff in that new
manifestation; nor was Gussy, she whose very existence had been wrapped
up in that of Meredith, who had only lived to watch him for weeks past,
recognizable. It was she who came out the last, but who made herself the
first of the group.
“There may be a great many things to say,” said Gussy; “but not to-
night. We have all had a great many agitations to-night. My brother has
been hunted for his life. My mother has done a thing which, so far as we
know, she hasn’t been able to do for years. Mr. Meredith has had a bad
illness, for which it appears this unfortunate family is responsible too. I
only and my little sister”—she paused here with an effort—“no; I will not
pretend; I have had my share of the shock, too. We’d better all separate for
the night.”
“Gussy!” cried Mrs. Harwood, with a sharp tone of appeal.
“Gussy!” cried Meredith, astonished, trying to take her hand to draw her
towards him.
“Gussy!” said Dolff, with a certain indignation.
“It is of no use,” she said, quickly, “to appeal to me. I think I am the one
who has been deceived all round. I thought I knew everything, and I’ve
known nothing. Whatever may be the meaning of it, I for one am not able
for any more to-night, and none of the rest ought to be able for it. I don’t
know whether I may have been deceived there, too, about how much
invalids could bear. Good-night, mamma. I advise you to get to bed.”
Gussy waved her hand to the others without a word, and walked upstairs
without turning her head. The sudden failure of a perfect faith in all the
world, such as she had entertained without entering into complications for
which her mind was not adapted, is no small matter. It is alarming even for
others to see. They all stood for a moment huddled together as if a rock or a
tower had fallen before their eyes. They could scarcely see each other for
the dust and darkness it made. All the other events of this startling night
seemed to fall into the background. Gussy! who had been the central prop
of the house, who had kept everybody together, done everything! When she
thus threw up her arms they were all left in dismay, and fell into an
assemblage of atoms, of units—no longer a united party ready to meet all
comers.
Meredith, perhaps, he who had been the most eager, was the most
discomfited of all. He had claimed Gussy’s interest as his right for years.
When she thus withdrew, not even asking if he were fatigued, speaking
almost as if she thought that fatigue a pretence, he was so bewildered that
he could do nothing. An anxious believer like this is accepted perhaps with
too much faith and considered too inalienable a possession; and when she
fails the shock is proportionately great. Without Gussy to stand by him, to
make him believe himself a universal conqueror, always interesting, always
important, Meredith for the moment was like an idol thrown from his
pedestal. He was more astonished than words could say. He exclaimed,
hurriedly,
“I think Gussy is right, as she always is. Mrs. Harwood, I will say good-
night.”
Mrs. Harwood was altogether in a different mind. The period of reaction
had not come with her as yet. She had got herself deposited in her chair in
time enough to save her from any breaking down. And her spirit was full of
excitement.
“I am ready,” she said, with a panting hot breath of mental commotion,
“to explain—whatever it is necessary to explain. Take me back to my room,
Dolff. It is cold here.”
“Good-night,” said Meredith. “I will not encroach upon you longer to-
night.”
“As you like,” she said. “I warn you, however, that to-morrow——
Dolff, take me back to my fire.”
Dolff was unsubdued, like his mother. The reaction from a long period of
suspense, and the sense of safety after a great alarm, no doubt acted upon
his mind: though, so far as he was aware, he was moved by nothing save the
overwhelming discovery he had made, and his indignant sense of wrong in
finding such a secret retreat unsuspected, in his mother’s—in his own—
house.
“We’ll be better alone,” he said, in the stern tone which was so new to
him, putting his hand upon her chair; “but perhaps you could walk if you
tried,” he added, with rude sarcasm.
He drove rather than wheeled her before him into the deserted room,
where all was so brilliant and warm, the light blinking in the bright brass
and steel, the lamps serenely burning, everything telling of the tranquil life,
unbroken by any but cheerful incidents, which had gone on there for so
many years.
“Now, mother,” said Dolff, “we have got to have it out. Who is that man
upstairs?”
Julia had followed them unremarked, and remained behind her mother’s
chair. Dolff stood before them, in the full firelight, very erect, inspired with
indignation and that sense of superiority which injury gives. It had elevated
him altogether in the scale of being. His own shortcomings had fallen from
his consciousness. He was aware of nothing but that he, Dolff, in reality the
head of the family, had been deceived and compromised.
Mrs. Harwood took but little notice of her son. She took up her work
which had been thrown upon the table and turned it over in her fingers.
“Gussy was right,” she said, “though she was a little brusque in her way
of saying it. I am certainly unable to bear anything more to-night.”
“I suppose, however, you can answer my question,” said Dolff.
“Go to bed, boy,” said his mother, “and don’t worry me. We have two or
three things to talk over, you and I, which are too much for to-night.”
“I am not a boy any longer,” cried Dolff; “you have made me a man.
Who is it you have been hiding for years upstairs?”
She gave vent to a little fierce laugh.
“For my pleasure,” she said; “for my amusement, as anybody may see.”
“Whether it is for your amusement or not,” said Dolff, “I am of age, and
I have a right to know who is living in my house.”
“In your house!” Her exasperation was growing. “Don’t force me, Dolff,
to go into other questions to-night.”
“Whose house is it?” he said. “There’s been no question, because you
have kept everything in your hands; but if I am to be driven to it, and claim
my rights——”
“Your rights!” she cried, again repeating his words. “Was it one of your
rights to knock down a man like a coward from behind? It appears this is
what you think you may be permitted to do with impunity—to have your
home searched in every corner and to destroy all that I have been doing for
years, and to bring shame and disgrace to a house that I have kept free of
shame, almost at the risk of my life!”
“I did not,” cried Dolff, interrupting her eagerly. “I did not knock him
down from behind. I had not time to think. I let fly at him as I passed. It’s a
lie to say I knocked him down from behind.”
“You did the same thing; you took him unawares. And you dare to
question me! You killed a man at my door—or meant to do it—and never
breathed a word to warn us, to keep us from the disgrace——”
Dolff was not clever enough to know what to say. His snort of rage was
not attended by any force of bitter words. He only could repeat, with rage
and incompetence,
“At your door?”
“Perhaps,” said Mrs. Harwood, half carried away by passion, half
influenced by the dismay which she knew she had it in her power to call
forth, “it would be better, since you are exact, to say at your father’s door.”
Dolff responded with a strange cry. He did not understand it, but he felt
all the same that a blow which stunned him had been directed at him, and
that the ground was cut from beneath his feet.
“He has neither been tried, nor sentenced, nor anything proved against
him,” cried Mrs. Harwood, carried away now by the heat of her own
excitement. “All that has to be gone through before he can be put aside.
And at this moment everything’s his—the roof that covers you, the money
you have been spending. It is no more your house—your house!—than it is
Julia’s. It is your father’s house.”
“My father is dead,” said Dolff, who had again grown very pale, the
flush of passion dying out of his face.
“Yes,” said Mrs. Harwood, “and might have remained so, had it not been
for your cowardly folly and Vicars’s infatuation for you. How was it the
man had not the sense to see that a fool like you would spoil all?”
“You are dreaming, you are mad,” said Dolff; “you are telling me
another lie.”
But, though he said this with almost undiminished passion, the young
fellow’s superiority, his erect pose, his sense of being able to cow and
overwhelm her, had come to an end. He fell into his usual attitude, his
shoulders dropped and curved, his head hung down. He could fling a last
insult at his mother, but no more. And his own mind began to be filled with
unfathomable dismay.
Julia had been very uncertain what side to take. Her mind went naturally
with her brother, who was most near herself. But a mother is a mother after
all. You may feel her to be in some way your natural enemy when the
matter is between yourself and her; but when another hand plucks at her it
is different. A girl is not going to let her mother be insulted, who after all
means her own side, without interposing. Julia suddenly flew forth from
behind her mother’s chair and flung herself upon Dolff’s arm, seizing it and
shaking him violently.
“How dare you speak to her like that?” cried Ju, “you that can’t do
anything you try—not even kill Charley Meredith when you have the
chance! I should be ashamed to look any one in the face. Go away, go away,
and leave us quiet, you that have done it all: that brought the police into the
house, and yet did not hurt him to speak of, you great, useless,
disappointing boy!”
Dolff did not know how to sustain this sudden assault. He looked round
stupidly at the active assailant at his shoulder with a little pang, even in his
agitated and helpless state, to find that Julia was no longer on his side. His
head was going round and round: already in his soul he had entirely
collapsed, although he still kept his feet in outward appearance. And it
would have been difficult to end this scene without an entire breakdown on
one side or the other, had not the pensive little voice of the parlor-maid
become audible at this moment over their heads, making them all start and
draw back into themselves.
“If you please, ma’am,” said Priscilla, “for I can’t find Miss Gussy—
shall I take Mr. Meredith’s tray to his room, or shall I bring it in here?”
“I think Mr. Meredith is going to bed,” said Mrs. Harwood; “he is a little
tired. Take it into his room, Priscilla. And Miss Gussy has gone to bed; you
may come now and help me to get into my room, and then shut up
everything. It is later than I thought.”
“Yes, ma’am,” said Priscilla, in those quiet tones of commonplace which
calm down every excitement.
Priscilla indeed was herself bursting with curiosity and eagerness to find
out what had happened. The long-shut-up door stood ajar, and every maid
in the house had already come to peep into the dark passage and wonder
what it led to: and the keenest excitement filled the house. But a parlor-
maid has as high a standard of duty as any one, were it an archbishop. It
was against the unwritten household law to show any such commotion. She
took hold of the handle of her mistress’s chair as she did on the mildest of
domestic evenings, and drew her very steadily and gently away. The only
revelation she made of knowing anything was in the suggestion that a little
gruel with a glass of wine in it would be a proper thing for Mrs. Harwood to
take.
“You may bring me the glass of wine without the gruel,” Mrs. Harwood
was heard saying as the sound of her wheels moved slowly across the hall,
an hour ago the scene of such passionate agitation. “I don’t think I have
caught cold. A glass of wine—and a few biscuits,” she said as by an
afterthought.
Was this part of the elaborate make-believe intended to deceive the
servants and persuade them that nothing particular had happened? or was
she indeed capable of munching those biscuits after such a night of fate?
“Ju, don’t you turn against me,” said Dolff, feebly, throwing himself into
a chair when they were thus left alone.
“Oh!” cried Julia, still panting with her outburst, “to think you had hold
of him and didn’t really hurt him, not to matter! I can never, never forgive
you, Dolff.”
“Oh, hold your tongue, you little fool; the only thing I’m glad of is that I
didn’t hurt him—to matter! You don’t know what it is to live for a long
week, all the time he was insensible, thinking you have killed a man!”
“When it was only Charley Meredith!” Julia said.
CHAPTER XLIV.
It was strange that it should be Gussy, who was not ideal or visionary,
but very matter-of-fact in all her ways, who was the most cruelly offended
and wounded by the events of this night. It seemed to Gussy that she had
been deceived and played upon by everybody. By her mother, who had
never confided to her the gravity of the position, though she had known the
fact for years; by Meredith, who had seemed to know more of it than Gussy
did, and whose eyes had been keen with understanding, following every
word of what was to Gussy merely the ravings without consequence of a
madman; he knew more of it than she did, who had helped to take care of
the secret inmate. And then Dolff, her brother. What was the meaning of
this cloud of tempest which had come into Dolff’s trivial, schoolboyish life?
Why had he tried to kill, if that was what he wanted, or, at least, to injure, to
assault Meredith?
It was all a mystery to Gussy. She understood nothing except that many
things had been going on in the house which she either did not know at all
or knew imperfectly—that she had been possibly made a dupe of, brought
down from the position which she had seemed to hold of right as the chief
influence in the family. She had thought this was how it was: her mother’s
confidant, the nurse and guardian-angel of her lover, the controller, more or
less, of all the house. And it turned out that she knew nothing, that there
were all kinds of passions and mysteries in her own home with which she
was unacquainted, that what she knew she knew imperfectly, and that even
in the confidences given to her she had been kept in the dark.
Gussy was not imaginative, and consequently had little power of
entering into the feelings or divining the movements of the minds of others.
She was wounded, mortified to the depths of her heart, and angry, with a
deep, silent anger not easily to be overcome. She did not linger nor ask for
explanations, but went straight up to her room without a moment’s pause,
careless that both her mother, whom she generally attended through the
troublesome process of undressing, and Julia, whom she usually held under
such strict authority, were left behind, the latter in contempt of all ordinary
hours. Janet, whose charge that was, was not visible; she had stolen away,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like