Instant download (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 pdf all chapter
Instant download (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 pdf all chapter
com
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
ebooknice.com
(Ebook) Linux : introduce to beginners guide + UNIX
operating system + Linux shell scripting and command line
+ Linux System by Erickson Karnel & CODING HOOD ISBN
B0B2HP36XR
https://ebooknice.com/product/linux-introduce-to-beginners-guide-unix-
operating-system-linux-shell-scripting-and-command-line-linux-
system-43317364
ebooknice.com
ebooknice.com
https://ebooknice.com/product/pro-bash-programming-scripting-the-gnu-
linux-shell-1365422
ebooknice.com
ebooknice.com
ebooknice.com
Mastering Linux Shell Scripting
Second Edition
"QSBDUJDBMHVJEFUP-JOVYDPNNBOEMJOF#BTITDSJQUJOHBOE
4IFMMQSPHSBNNJOH
Mokhtar Ebrahim
Andrew Mallett
BIRMINGHAM - MUMBAI
Mastering Linux Shell Scripting
Second Edition
Copyright a 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.
ISBN 978-1-78899-055-4
XXXQBDLUQVCDPN
NBQUJP
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
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 XXX1BDLU1VCDPN and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at TFSWJDF!QBDLUQVCDPN for more details.
At XXX1BDLU1VCDPN, 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
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!
[ ii ]
Table of Contents
[ iii ]
Table of Contents
Questions 119
Further reading 120
Chapter 7: Creating Building Blocks with Functions 121
Technical requirements 121
Introducing functions 122
Passing parameters to functions 125
Passing arrays 128
Variable scope 129
Returning values from functions 130
Recursive functions 132
Using functions in menus 133
Summary 135
Questions 135
Further reading 136
Chapter 8: Introducing the Stream Editor 137
Technical requirements 138
Using grep to display text 138
Displaying received data on an interface 138
Displaying user account data 139
Listing the number of CPUs in a system 140
Parsing CSV files 143
The CSV file 143
Isolating catalog entries 145
Understanding the basics of sed 146
The substitute command 147
Global replacement 148
Limiting substitution 150
Editing the file 150
Other sed commands 151
The delete command 151
The insert and append commands 152
The change command 153
The transform command 153
Multiple sed commands 154
Summary 154
Questions 155
Further reading 156
Chapter 9: Automating Apache Virtual Hosts 157
Technical requirements 158
Apache name-based Virtual Hosts 158
Creating the virtual host template 159
First steps 160
[ iv ]
Table of Contents
[v]
Table of Contents
Questions 210
Further reading 210
Chapter 12: Summarizing Logs with AWK 211
Technical requirements 211
The HTTPD log file format 212
Displaying data from web logs 213
Selecting entries by date 213
Summarizing 404 errors 215
Summarizing HTTP access codes 215
Resources hits 217
Identify image hotlinking 218
Displaying the highest ranking IP address 219
Displaying the browser data 220
Working with email logs 221
Summary 221
Questions 222
Further reading 222
Chapter 13: A Better lastlog with AWK 223
Technical requirements 223
Using AWK ranges to exclude data 224
The lastlog command 224
Horizontally filtering rows with AWK 225
Counting matched rows 225
Conditions based on the number of fields 226
Manipulating the AWK record separator to report on XML data 228
Apache Virtual Hosts 228
XML catalog 229
Summary 231
Questions 232
Further reading 232
Chapter 14: Using Python as a Bash Scripting Alternative 233
Technical requirements 233
What is Python? 234
Saying Hello World the Python way 236
Pythonic arguments 236
Supplying arguments 237
Counting arguments 237
Significant whitespace 239
Reading user input 240
Using Python to write to files 241
String manipulation 242
[ vi ]
Table of Contents
Summary 243
Questions 244
Further reading 244
Assessments 245
Other Books You May Enjoy 252
Index 255
[ vii ]
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.
$IBQUFS, Creating Interactive Scripts, covers how to read input from the user using SFBE
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.
$IBQUFS, Conditions Attached, will introduce the JG statement, the DBTF statement, and
other testing command such as FMTF and FMJG.
$IBQUFS, Creating Code Snippets, covers creating and using code snippets using editors,
such as vim and Visual Studio Code.
$IBQUFS, Alternative Syntax, will discuss advanced testing using << and how to perform
arithmetic operations.
$IBQUFS, Iterating with Loops, will teach you how to use GPS loops, XIJMF loops, and
VOUJM loops to iterate over simple values and complex values.
$IBQUFS, Creating Building Blocks with Functions, will introduce functions and explains
how to create a function, list builtin functions, pass parameters to functions, and writing
recursive functions.
$IBQUFS, Introducing the Stream Editor, will introduce the basics of sed tool to manipulate
files, such as adding, replacing deleting, and transforming text.
$IBQUFS, Automating Apache Virtual Hosts, contains a practical example of sed and
explains how to create virtual hosts automatically using sed.
$IBQUFS, AWK Fundamentals, will discuss AWK and how to filter file content using it.
Also, we will discuss some AWK programming basics.
$IBQUFS, Regular Expressions, covers regular expressions, their engines, and how to use
them with sed and AWK to empower your script.
$IBQUFS, Summarizing Logs with AWK, will show how to process the IUUQEDPOG
Apache log file using AWK and extract useful well-formatted data.
[2]
Preface
$IBQUFS, A Better lastlog with AWK, will show you how to use AWK to output beautiful
reports using the lastlog command by filtering and processing the lastlog output.
$IBQUFS, Using Python as a Bash Scripting Alternative, will discuss Python programming
language basics and explains how to write some Python scripts as a bash script alternative.
You should know some Linux basics such as the basic commands such as MT, DE, and
XIJDI.
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
The code bundle for the book is also hosted on GitHub at IUUQTHJUIVCDPN
1BDLU1VCMJTIJOH.BTUFSJOH-JOVY4IFMM4DSJQUJOH4FDPOE&EJUJPO. 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 IUUQTHJUIVCDPN1BDLU1VCMJTIJOH. Check them out!
[3]
Preface
Conventions used
There are a number of text conventions used throughout this book.
$PEF*O5FYU: 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 )0.&CJOIFMMPTI"
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"
[4]
Preface
Get in touch
Feedback from our readers is always welcome.
General feedback: Email GFFECBDL!QBDLUQVCDPN 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 RVFTUJPOT!QBDLUQVCDPN.
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 XXXQBDLUQVCDPNTVCNJUFSSBUB, 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 DPQZSJHIU!QBDLUQVCDPN 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
BVUIPSTQBDLUQVCDPN.
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!
[5]
1
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.
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: IUUQTDPEFWJTVBMTUVEJPDPN.
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 CBTIEC, 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
The shell translates your commands and sends them to the system. Most Linux
distributions are shipped with many shells.
[7]
The What and Why of Scripting with Bash Chapter 1
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?
As you might know, you can run multiple commands from the shell by separating them
with semi colons ():
ls ; pwd
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 JG
statement, or FMTF or XIJMF loops. All are Linux executables.
You can say that the shell is the glue that binds these commands together.
[8]
The What and Why of Scripting with Bash Chapter 1
Command type
For example, if we type and enter MT 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 UZQF command can come to our aid here.
The UZQF 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 MT.
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
[9]
The What and Why of Scripting with Bash Chapter 1
If we need to just type in the output, we can use the U 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 UZQF can also be used to identify shell keywords such as JG, and DBTF. The
following command shows UZQF being used against multiple arguments and types:
$ type ls quote pwd do id
You can also see that the function definition is printed when we stumble across a function
when using UZQF.
Command PATH
Linux will check for executables in the 1"5) 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 1"5). It is possible to include our current directory within the 1"5) by adding the
directory to the 1"5) variable. This is shown in the following command example:
$ export PATH=$PATH:.
[ 10 ]
The What and Why of Scripting with Bash Chapter 1
This appends the current directory to the value of the 1"5) variable; each item in the 1"5)
is separated using a colon. Now your 1"5) 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 CJO within your home directory and add the scripts
into that folder. Adding )0.&CJO to your 1"5) 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 CJO directory or not. The use of the
)0.& 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 )0.&CJO directory so that
they can be executed regardless of our working directory.
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.
[ 11 ]
The What and Why of Scripting with Bash Chapter 1
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, )0.&WJNSD.
When these options are set, the )0.&WJNSD file should look similar to this:
TFUTIPXNPEF
TFUOPIMTFBSDI
TFUBVUPJOEFOU
TFUUBCTUPQ
TFUFYQBOEUBC
TZOUBYPO
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 )0.&OBOPSD file. Your
edited file should look something like the following:
TFUBVUPJOEFOU
TFUUBCTJ[F
JODMVEFVTSTIBSFOBOPTIOBOPSD
[ 12 ]
The What and Why of Scripting with Bash Chapter 1
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
IUUQXXXQBDLUQVCDPN for all the Packt Publishing books you have
purchased. If you purchased this book elsewhere, you can visit
IUUQXXXQBDLUQVCDPNTVQQPSU and register to have the files e-mailed
directly to you.
[ 13 ]
The What and Why of Scripting with Bash Chapter 1
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:
For the rest of the book, we will be working on the command line and in vim; feel free to
use the editor that you work with best. We have now laid the foundations to create good
scripts, and, although whitespace, tabs, and spaces in bash scripts are not significant, a well-
laid-out file with consistent spacing is easy to read. When we look at Python later in the
book, you will realize that in some languages, the whitespace is significant to the language
and it is better to adopt good habits early on.
[ 14 ]
The What and Why of Scripting with Bash Chapter 1
Hello World!
As you know, it is almost obligatory to begin with a )FMMP8PSME script and we will not
disappoint as far as this is concerned. We will begin by creating a new
script, )0.&CJOIFMMPTI. The contents of the file should read as in the following
screenshot:
We hope that you haven't struggled with this too much; it is just three lines, after all. We
encourage you to run through the examples as you read to really help you instill the
information with good hands-on practice.
CJOCBTI: Normally, this is always the first line of the script and is known as
the shebang. The shebang starts with a comment, but the system still uses this
line. A comment in a shell script has the symbol. The shebang instructs the
interpreter of the system to execute the script. We use bash for shell scripts, and
we may use PHP or Perl for other scripts, as required. If we do not add this line,
then the commands will be run within the current shell; it may cause issues if we
run another shell.
FDIP)FMMP8PSME: The FDIP command will be picked up in a built-in shell
and can be used to write a standard output, 45%065; this defaults to the screen.
The information to print is enclosed in double quotes; there will be more on
quotes later.
FYJU: The FYJU command is a built-in shell, and is used to leave or exit the
script. The FYJU code is supplied as an integer argument. A value of anything
other than will indicate some type of error in the script's execution.
[ 15 ]
The What and Why of Scripting with Bash Chapter 1
We should be rewarded with the )FMMP8PSME text being displayed on our screens. This is
not a long-term solution, as we need to have the script in the )0.&CJO directory,
specifically, to make running the script easy from any location without typing the full path.
We need to add in the execute permissions as shown in the following code:
$ chmod +x $HOME/bin/hello1.sh
We should now be able to run the script simply, as shown in the following screenshot:
In the preceding example, DPNNBOE is executed only if DPNNBOE fails in some way. To be
specific, DPNNBOE will run if DPNNBOE exits with a status code other than .
Similarly, in the following extract, we will only execute DPNNBOE if DPNNBOE succeeds
and issues an exit code of :
$ command1 && command2
To read the exit code from our script explicitly, we can view the variable, as shown in the
following example:
$ hello1.sh
$ echo $?
The expected output is , as this is what we have added to the last line of the file and there
is precious little else that can go wrong to cause the failure to reach that line.
[ 16 ]
Exploring the Variety of Random
Documents with Different Content
carried back a long way to Boston, New York, Philadelphia, and
other parts of the East.
Glass mills form an important part of the city’s industries and
have been in operation for a long time. Bottle glass is manufactured
here, besides three fourths of all the plate glass of the United States.
Perhaps it is because bottles are made in Pittsburg that we find here
also the largest cork factory in the world.
Pittsburg is proud of the fact that she handles more tons of
freight in a year than any other city in the world. Indeed, the tonnage
is greater than that of New York and Chicago taken together.
The old “point” between the rivers is filled with tall buildings.
Inclined railways run up the steep bluffs on the further side of each
river and lead to the beautiful streets and the homes where many of
the people live. For Pittsburg is not all coal and furnaces and smoke,
but has fine churches, the great Carnegie Library and Museum, and
many schools. But it is mostly because of the coal and the rivers that
we find here a splendid city.
Sixty-three miles down the Ohio river, on its left bank, is
Wheeling, the largest city in West Virginia. The business streets lie
close to the Ohio, and the houses extend up the steep slope to the
east, while over a high ridge comes the old National Road from the
valley of Wheeling creek. Wheeling was the goal of many heavily
laden wagons in the days of the pike, and because of the river and
many railroads has a large trade to-day. It was settled in 1770 and is
one of the oldest towns on the river.
On the north bank of the great stream, in the southwest corner of
Ohio, is the largest city on the river. As late as 1900 Cincinnati had a
few thousand more people than Pittsburg, but a “greater Cincinnati”
would not be so large as a “greater Pittsburg.”
In Cincinnati, as in Pittsburg, men do business on the low
grounds by the river, where offices and mills and shops crowd one
another, and the smoke of soft coal hangs as a cloud above.
Business hours over, the well-to-do merchants climb out of the grimy
town to the top of the bluffs, and there find, in a clearer air and along
open and beautiful avenues, their comfortable homes. Down town
the turbulent river sometimes comes up forty or fifty feet beyond its
usual level and makes trouble in the busy city, but Mt. Auburn and
Walnut Hills are disturbed neither by smoke nor by floods.
Rivers do not often flow in straight lines, and it is very common
for them to change their courses along their flood plains. This habit
of shifting belongs alike to great and small streams, whether the
Mississippi or the brook in the meadow. The Ohio, like other rivers,
often writes the letter S, and in so doing at this point has swung off
from its old north bank, leaving a low plain with room enough for a
hundred thousand people to carry on their business. There is always
some good reason which has led to the settlement and growth of a
town, and the history of Cincinnati shows no exception.
It was in early winter, 1788, when cakes of ice were already
floating on the river, that a number of men sailing downstream
stopped here and began a settlement. The place was not readily
named. It is said that the matter was left to a frontier schoolmaster,
and he did not lose the chance to show how much he knew. He saw
that the Licking river comes into the Ohio on the Kentucky side just
opposite. So he set down an L. He next remembered an ancient
word os, meaning “mouth,” and he put that down. Then he
considered that anti means “opposite” and that ville means “town.”
So he wrote the whole name,—L-os-anti-ville,—Losantiville,—“the
town opposite the mouth of Licking.”
We might wonder whether a town with a name like that would
ever grow into a great city. It did not have to try, for it was not long
before General St. Clair, who had come there, made fun of the name
and insisted upon a new one. He and other officers of the American
army had formed a society commemorating their experience in the
Revolution, and in honor of the Roman patriot Cincinnatus had called
themselves the Order of Cincinnati. St. Clair thought this a good
name for the town, and Cincinnati it has been since that time.
The place has its nickname also, and its people like to call it the
Queen City, which seems to go very well with Beautiful River.
Another name, rarely used and not very pleasing, perhaps, to those
who live there, is “Porkopolis,” which came from the fact that for forty
years before the American Civil War more pork packing was done in
Cincinnati than anywhere else in the country.
Fig. 52. Hilly Farm Lands in the Great Valley, near Knoxville
Besides the Scotch-Irish, there were many Germans who had
followed the valley from Pennsylvania, and there were Huguenots
also, besides a few Hollanders and Swedes. A fort was built on the
little river, and around this defense grew up the Watauga Settlement.
There was no Tennessee in those days.
Many of the settlers had followed down the valleys from earlier
homes in Virginia, and it never occurred to them that they were not
still living in Virginia, and able to call on the colony for help. But after
a time a man came to the settlement who was a surveyor, and for
some reason he thought that he would run the boundary line of
Virginia farther west. When he had done it, what was the surprise of
every one to find that they were not in Virginia at all! If they belonged
to any colony, it was to North Carolina. Unfortunately there was a
lack of good government in that colony, and the prospect of
belonging to it was not a pleasant one; indeed, some of the settlers
had run away from North Carolina, and had felt safer because the
great mountains rose between them and their former home.
There seemed nothing to do but to make a government of their
own, so they formed the Watauga Association, about which writers of
American history have said a good deal. It would be interesting to
see a copy of the constitution that was drawn up by these
backwoodsmen, but it has been lost, with little hope that it will ever
be recovered. It is known, however, that there was a committee of
thirteen, really a legislature. This committee chose five of their own
number to form a court, which had a clerk and a sheriff and made
laws for all the settlers. Roosevelt, in his Winning of the West, says
that these pioneers were the first to build a “free and independent
community” in America.
The two most important men of this little state in the wild forest
show us that the settlers came from widely different places. James
Robertson was one, and he came over the mountains from North
Carolina. John Sevier was the other, and he came down the valley
from Virginia. We shall need to know what sort of men these were.
James Robertson belonged to the Scotch-Irish people. He was
not one of the very first settlers at Watauga, but came in the second
year, 1770. He had no early education, and his wife, an intelligent
woman, taught him to read. He went alone over the mountains, with
only his horse and gun, in search of a place for a home. He found
the settlers and admired the place which they had chosen, but on his
way back in the fall he lost his horse and got his powder wet. He
wandered about, almost starved, until he met some hunters, who
helped him home. He told his neighbors of the lands in the valley,
and as soon as the winter was over his own family and sixteen
others started out for Watauga. He built a log house, went to work on
the land, and by his wisdom and energy soon came to be a leader of
the new colony.
John Sevier did not come until 1772. His father had been a
settler in the Shenandoah valley, and John followed the streams, as
we have traced them, to the Great Valley. He was by birth a
gentleman, using that word to mean a man born of cultivated parents
and familiar with the world. He was well educated and was
acquainted with prominent men, such as Franklin and Madison. Both
he and Robertson were good fighters, as we shall see.
It was not long before seven hundred Indian warriors, angry
because the white people had made homes on their hunting
grounds, stole in upon the settlement. An Indian woman, Nancy
Ward by name, who felt kindly toward the whites, secretly warned
them of the attack, so that when the savages came they found all the
men, women, and children in the fort. It was not much of a fort, but it
saved their lives. The Indians kept up the attack for six days, but the
colonists, led by Sevier and Robertson, held out against them and
killed a number of their braves. When nearly a week had passed the
red men, tired of the siege, went off through the forest.
Fig. 53. From the Pinnacle, Cumberland Gap, looking
Northeast along the Cumberland Mountains. The
Great Valley at the Right
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.
ebooknice.com