Instant Download (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 PDF All Chapters
Instant Download (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 PDF All Chapters
com
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
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
ebooknice.com
https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
ebooknice.com
ebooknice.com
ebooknice.com
Mastering Linux Shell Scripting
Second Edition
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.
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
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
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
Conventions used
Get in touch
Reviews
Technical requirements
Command PATH
Configuring vim
Configuring nano
Configuring gedit
Hello Dolly!
Declaring variables
User-defined variables
Environment variables
Variable scope
Command substitution
Summary
Questions
Further reading
Technical requirements
Script comments
Try to be standard
Enhancing learning with simple scripts
Further reading
3. Conditions Attached
Technical requirements
Simple decision paths using command-line lists
Testing strings
Testing integers
Checking strings
Checking files and directories
Checking numbers
Combining tests
Summary
Questions
Further reading
4. Creating Code Snippets
Technical requirements
Abbreviations
Questions
Further reading
5. Alternative Syntax
Technical requirement
Recapping the test command
Testing files
Adding logic
Square brackets as not seen before
Setting defaults
When in doubt – quote!
Advanced tests using [[
White space
Summary
Questions
Further reading
6. Iterating with Loops
Technical requirement
for loops
Advanced for loops
The IFS
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
Limiting substitution
Editing the file
Other sed commands
The delete command
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
Anchor characters
The dot character
The character class
Ranges of characters
Using grep
Summary
Questions
Further reading
12. Summarizing Logs with AWK
Technical requirements
Resources hits
Identify image hotlinking
Summary
Questions
Further reading
Summary
Questions
Further reading
What is Python?
Supplying arguments
Counting arguments
Significant whitespace
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
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.
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.
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.
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
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.
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 https://githu
b.com/PacktPublishing/Mastering-Linux-Shell-Scripting-Second-Edition. In case
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.
┌──┬──┐
│ 1│2 │
├─┬┴┬─┤
│3│4│5│
└─┴─┴─┘
Observ. 2d. The Learner must rightly apprehend the places of
the notes, which I think cannot better be done than by this means.
Considering that the notes of a peal of bells do all strike one after
another at the fore-stroke, and the like at back-stroke; it might be
requisite for him to imagine, that the notes in their striking do lie in
a direct line, that is, in a row at the fore-stroke, and the like again at
back-stroke; for then the places of the notes will much resemble the
places of the figures wherewith the changes are prickt: for as the
figures of every change do all stand in a row; so likewise the notes of
the bells, being imagined to strike in the like row, he may the more
readily apprehend the places of the notes, and consequently of
changing them. For the practick part of this Art, is performed by
means of imaginary, not real notions; which will thus manifestly
appear. This is the platform of a Frame, wherein five bells may be
supposed to hang in a Steeple, the figures therein representing the
places wherein the five bells hang. Now in the sixscore changes on
five bells, we will suppose the Treble to be the whole Hunt, and to
hunt up first over the Second, then over the Third, &c. Now the
Treble cannot really move out of the place wherein it hangs; but by
delaying its striking untill the Second Bell has struck, it may by that
means strike next after it; and again, by delaying its striking until the
Third has struck; it may also strike next after that, this being the true
manner of the changes; by which ’tis evident, that the bells have
neither really such places nor motion as is pretended, but is meerly
imaginary, and was at first feigned only as a Guide to direct the
Practitioner’s apprehension in the ringing of them. So that although
the art of changes is in it self a real thing, yet the notions by which
they are reduced to practice on bells, are not so. For which reason,
the several practitioners of this Art, before they can become expert,
are fain to form in their minds imaginary notions to guide them;
some after one manner, some perhaps after another, according to
their several fancies, yet all tending, to render the methods of
changes practicable on bells; and having once form’d in their minds
such imaginary helps, they become expert in short time: and then no
sooner do they understand the methods of changes prickt with
figures, which they commonly discover at first view; but they are
presently capable of ringing them readily on bells, which experience
daily testifies. And hence it is, that oftentimes the Learners, although
they perfectly understand the methods of changes prickt, and also
can perfectly manage a Bell; yet for want of a right apprehension of
the nature of changing the notes, which of themselves it may be they
cannot soon attain, are therefore much puzzled in their first practice
of ringing changes. Therefore as a guide, the Learner must first form
in his mind a fit representation of the places of the notes; which I
think cannot better be done, than by imagining each note to be a
figure; as the Treble-note to be the figure 1, the second note the
figure 2, the third note the figure 3, and the like of the rest. Then
whensoever he hears a peal of bells ring, let him by strength of
imagination conceit, that each note bears the shape of a figure; that
is, at the same instant of time that the note strikes, he may imagine
that it leaves the impression of the figure behind it, and that with the
eye of his imagination he perfectly sees it: and likewise as the notes
of the bells do all strike after one another at the fore-stroke, so he
may imagine that they lie in a row in the shape of figures; and the
like again at back-stroke. For instance: suppose that five Muskets
were charged with five bullets, and that each bullet bears the shape
of a figure; one Gun to be charged with the figure 1, another with the
figure 2, and the other three Guns with these three figures, 3. 4. 5.
Then supposing a straight line were drawn upon the wall, thus
—————————— and that the five Muskets were by five men
levell’d against the line, which is to be the mark for them to shoot at;
the figure 1 to be first shot off, then the figure 2, and so the rest in
order immediately after one another: now at the same instant of time
that the Guns are heard to go off, the five figures would appear in a
3241
1342
4321
1423
2431
1234
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