100% found this document useful (1 vote)
32 views

Mastering Linux Shell Scripting a practical guide to Linux command line Bash scripting and Shell programming Ebrahim download

The document is a promotional overview of the book 'Mastering Linux Shell Scripting' by Mokhtar Ebrahim, which serves as a practical guide to Linux command line, Bash scripting, and shell programming. It includes links to various related resources and other books on Linux scripting. The book covers topics such as creating interactive scripts, conditions, loops, functions, and using tools like AWK and sed.

Uploaded by

piousqushryc5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
32 views

Mastering Linux Shell Scripting a practical guide to Linux command line Bash scripting and Shell programming Ebrahim download

The document is a promotional overview of the book 'Mastering Linux Shell Scripting' by Mokhtar Ebrahim, which serves as a practical guide to Linux command line, Bash scripting, and shell programming. It includes links to various related resources and other books on Linux scripting. The book covers topics such as creating interactive scripts, conditions, loops, functions, and using tools like AWK and sed.

Uploaded by

piousqushryc5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Mastering Linux Shell Scripting a practical

guide to Linux command line Bash scripting and


Shell programming Ebrahim download

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

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Mastering Linux shell scripting a practical guide to


Linux command line Bash scripting and Shell programming
Second Edition. Edition Mokhtar Ebrahim

https://textbookfull.com/product/mastering-linux-shell-scripting-
a-practical-guide-to-linux-command-line-bash-scripting-and-shell-
programming-second-edition-edition-mokhtar-ebrahim/

Linux Shell Scripting Cookbook - Third Edition Clif


Flynt

https://textbookfull.com/product/linux-shell-scripting-cookbook-
third-edition-clif-flynt/

BASH SCRIPT Linux Command Line Reference 1st Edition


Aditya Tiwari

https://textbookfull.com/product/bash-script-linux-command-line-
reference-1st-edition-aditya-tiwari/

Shell Programming in Unix Linux and OS X Stephen G.


Kochan

https://textbookfull.com/product/shell-programming-in-unix-linux-
and-os-x-stephen-g-kochan/
The Linux Command Line: A Complete Introduction 2nd
Edition William E. Shotts

https://textbookfull.com/product/the-linux-command-line-a-
complete-introduction-2nd-edition-william-e-shotts/

Linux Basics for Hackers Getting Started with


Networking Scripting and Security in Kali Occupytheweb

https://textbookfull.com/product/linux-basics-for-hackers-
getting-started-with-networking-scripting-and-security-in-kali-
occupytheweb/

Wicked Cool Shell Scripts 101 Scripts for Linux OS X


and UNIX Systems Dave Taylor

https://textbookfull.com/product/wicked-cool-shell-
scripts-101-scripts-for-linux-os-x-and-unix-systems-dave-taylor/

Computing with the Raspberry Pi: Command Line and GUI


Linux 1st Edition Brian Schell

https://textbookfull.com/product/computing-with-the-raspberry-pi-
command-line-and-gui-linux-1st-edition-brian-schell/

Linux Basics for Hackers Getting Started with


Networking Scripting and Security in Kali 1st Edition
Occupytheweb

https://textbookfull.com/product/linux-basics-for-hackers-
getting-started-with-networking-scripting-and-security-in-
kali-1st-edition-occupytheweb/
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.


Another Random Scribd Document
with Unrelated Content
Photo by Brown Bros.
“The Great White Way”
Times Square, New York, at night, with Broadway on the
left, a curving ribbon of white light. Here every night in
winter thousands upon thousands of people throng to
theaters and cafés.

The next step in the development of Mr. Edison’s electric-lighting


system was taken on October 21, 1879, when he discovered that if a
carbonized cotton thread were substituted as a burner for the
platinum wire of his earlier lamp, the slender and apparently frail
carbon was mechanically strong, and also durable under the action of
the electric current. The announcement of the invention of the carbon
filament lamp was first made to the public in December, 1879.

Steam Dynamo in Edison’s Old Station

With the experience gained by an experimental system at Menlo Park,


Mr. Edison began, in the spring of 1881, at the Edison Machine
Works, Goerck Street, New York City, the construction of the first
successful direct-connected steam dynamo. The development of an
adequate underground conduit proved also most serious. The district
selected for lighting was the area—nearly a square mile in extent—
included between Wall, Nassau, Spruce, and Ferry Streets, Peck Slip
and the East River in New York City. In those days such electrical
transmission as existed—this of course related largely to telegraphy—
was accomplished by means of a veritable forest of poles and wires
augmented by the distribution equipments of fire alarm, telephone,
burglar alarm and stock ticker companies. So used had people
become to this sort of thing that even the most competent electrical
authorities of the time doubted extremely whether Edison’s scheme
of an underground system could be made either a scientific or a
commercial success, owing to the danger of great loss through
leakage. However, the Edison conduits once in use, both the public
and even the telephone, telegraph and ticker companies
acknowledged their feasibility. Such, in fact, was the success of the
new method that the city compelled at length the removal of all
telegraph poles.

In the Trenches.
The systematic laying out of street mains in the first company district
was begun in the summer of 1881. It must not be thought, of course,
that these old-time conduits resembled strikingly those of the present
day. The method then used was to dig a trench in which were laid the
pipes measuring twenty feet in length. Through these the conductors
were drawn, two half-round copper wires kept in place first by heavy
cardboard and afterward by rope. The conductors having been drawn
in, a preparation of asphaltum and linseed oil was forced into the
piping to serve as insulation. The spending of three and four arduous
nights a week in these trenches by Mr. Edison and his associates
suggests the rigor of the later European warfare. This work, together
with that incident to the operation of the new station, often proved
too much even for Edison’s phenomenal endurance. At such times he
slept on a cot close beside the running engines, while the rest of the
crew crawled in on the lower row of field-magnet coils of the
dynamos, a place warm enough, though a trifle bumpy. One of the
inventor’s early assistants tells of going to sleep standing up, leaning
against a door frame—this, after forty-eight hours of uninterrupted
work.
The Dynamo Room of the First Edison Electric Lighting Station
in New York

September 4th saw a full 400 lamps turned on from the Pearl Street
station. From that day on the station supplied current continuously
until 1895, with but two brief interruptions. One of these happened in
1883 and lasted three hours. The other resulted from the serious fire
of January 2, 1890, and lasted less than half a day. The record in the
second case would appear astounding, as no less a handicap
occurred than the burning down of the station itself. The situation
was saved, however, by the presence of an auxiliary plant that had
already been opened on Liberty Street.

Edison as a Central Station Pioneer.


The layman, while appreciating the tremendous advance in
generating machinery since the early eighties, is surprised to learn
that the great Edison system of today is conducted upon principles
that Edison developed and put into practice at that time. Edison’s, in
truth, was the master mind, the forming spirit of all the advances
made in the seventies and eighties. Exceedingly much, on the other
hand, is due the energy of his fellow workers, many of whom figure
conspicuously in the country’s electrical affairs at present.
[277]
Courtesy of Indiana Steel Co. Electric Power Station

The seventeen great gas engines are operated by gas from the blast furnaces
which was formerly allowed to escape. Each engine drives a 2,500-kilowatt
dynamo.

In this manner Edison and his assistants became established in New


York City. Current at first was supplied free to customers for
approximately five months, which speaks quite as much for Edison’s
Scotch “canniness” as for his inventive genius. Well before the period
was over the new illuminant had justified itself, until today it shows
itself an element indispensable in every phase of the country’s
activity.
Electric Delivery Wagons Loading Edison Lamps

Early Growth.
Within two years from the opening of the station the demand for
service had so increased that over one hundred applications were
filed in excess of what could be accepted, because the plant was
taxed already to its utmost capacity. Allusion has already been made
to the auxiliary plant at Liberty Street, a station of 2,000 lights’
capacity which was instituted in 1886. By 1887, not only a second but
a third district had been mapped out, the whole extending from
Eighteenth to Forty-fifth Street. All the underground system in the
two new districts was laid according to Edison’s new three-wire
patent; and it was presently announced that customers would be
supplied with power as well as with light.
Six months after the disastrous fire of 1890, in which the Pearl Street
station was burned, the site was chosen for the Edison Duane Street
building on which operations were so hastened that machines were
installed and current turned on the first of May the following year.

The Waterside Stations.


For some time the need of a central generating plant had been
apparent to all familiar with the company’s facilities and prospects.
Already during the summer of 1898 an engineering commission had
visited all the chief electrical stations of Europe and consulted the
best-known experts of the industry, and in 1902 the first waterside
station in New York was opened upon a site bordering the East River
between Thirty-eighth and Thirty-ninth Streets. The new operating
room contained sixteen vertical engines with a capacity each of over
5,000 horse-power. From these current was generated by 3,500
kilowatt generators and sent out to the various distributing centers.
As a very natural consequence of such development, the company by
1902 had 420 miles of underground system supplying installation
amounting to 1,928,090 fifty-watt equivalents.

Electricity a Living Factor.


To talk about electrical development in terms of power consumed
tells but one side of the story. More impressive even than figures are
the immense number of uses to which electricity is put. Electric
lighting, introduced in 1882, has become practically the standard for
illumination, not only here, but for the entire civilized world.

Electric Sewing Machines in the Manhattan Trade School

In the Printing Trade.


Electric power was introduced, timidly, by way of a few fans in 1884
and following this, in 1888, motor drive for printing presses was
undertaken. At the present moment in New York City there is hardly a
printing establishment worthy the name that is not electrically
operated throughout. Among the largest customers of the central
station in New York City are the great daily newspapers, among them
the Times, the World, the Sun, the Evening Post, and the American.

Construction.
Not only are passengers conveyed up and down by electric elevators
in skyscrapers, but the buildings themselves are erected by means of
electricity. Recent examples of such construction are the Woolworth
and Equitable buildings in New York City; in this last instance a
thousand horse-power was used in digging the foundations alone.
[280]

Photo by Brown Bros. A Fairyland of Light


The canyon of lower Broadway, south from the Woolworth Building—a glorious
miracle of light.
Not only are New York City’s subways operated by electricity; they
were also built by electricity, a statement which applies to the new
subways as well as the parts of the first system. In digging for the
new Broadway subway, an electric company supplied 25,000 horse-
power. The mammoth new aqueduct system by which water is carried
from the Catskills to the Battery is another example of electricity as a
source of power for large construction work. Still more picturesque is
the use of electricity in building the under-river tubes. Indeed, it is
doubtful whether this particular form of operation could have been
carried on without the aid of electricity.

Loft Manufacturing.
Aside from these special instances of electricity in construction, one
must think of electricity as responsible for nearly all the
manufacturing, large and small, that goes on in the ever-increasing
number of loft-buildings throughout all large cities. For example, New
York City serves as the center of the garment-making industry for the
entire country, there being fully a quarter of a million garment-trade
workers in the Greater City. Along Fifth and Fourth Avenues are found
the large establishments, electrically equipped throughout for cutting,
stitching and pressing, while even in the smallest shops on the East
Side foot-power machines have become almost a thing of the past.

Electric Heating.
The commercial use of electric heating is one of the more recent
electrical developments. For the most part, this also applies to the
garment trade and its closely allied clothing industries. In the
modernly equipped factories one finds electric flat irons, velvet
steamers and coffee urns. In the printing trade, electrically heated
linotype melting pots are being introduced successfully, while glue-
pots and sealing-wax melters can be seen in binderies and banking
institutions. Absence of fire risk accounts for the introduction of
electric heating units of different kinds into the motion-picture film
manufacturing industry, a rapidly growing province. The same
element of safety where inflammable substances are employed has
produced the electric japan oven and similar apparatus.

Electricity and Safety.


The importance of electricity in factory work cannot be over-
estimated. A shop fully equipped with electric machinery is the best
possible kind of shop for employee as well as for the owner. Motor-
driven machines are the safest possible kind, while absence of
overhead shafting and dangerous belts mean health as well as
security. In the electric shop, motor-driven blowers carry fumes and
dust away from the worker and bring fresh air in. Electrically driven
machinery is now regarded as the standard machinery. In the various
vocational schools in New York City at present both boys and girls are
taught to operate electrically driven machines, it being assumed that
those will be what the pupils will be called upon to operate when they
leave the school for the shop.

Electricity in Medicine.
Another domain of electric enterprise of the greatest value for the
country at large is the increasing use of electricity in medicine. The
most conspicuous element in this is the wide-spread acceptance of
the X-ray as a necessary tool of the medical profession. Newspapers
and magazines were full of the remarkable X-ray achievements of
surgeons in charge of the various European war hospitals. Those, of
course, were spectacular instances, but it should not be forgotten
that every day, in our great hospitals, the X-ray is proving itself
almost indispensable in the examination of the sick and injured.
Besides utilizing X-ray in the diagnosis of disease, the rays themselves
are employed in treatment of cancer and skin diseases. The oculist,
the dentist, indeed medical specialists of all kinds, are coming to
recognize the immense aid that electricity can give in its various
forms and applications.
The Great Press Room of “The New York Times” is all
Electrically Operated

Electric Vehicles.
The electric truck has already demonstrated itself as a safer and less
expensive rival of the gasoline delivery truck in many kinds of service.
In the boroughs of Manhattan and the Bronx alone, in New York City,
there were more than 2,000 such trucks in operation in 1916.
Counting both pleasure and business vehicles, the borough of
Manhattan boasted about 2,500 storage-battery driven wagons in
active use. It is rather interesting to note that Chicago operates many
more electric pleasure cars than New York, while New York does far
more of its business by means of the electric vehicle. Recently, there
was established in New York an electric co-operative garage, the joint
enterprise of the electric passenger car manufacturers and an electric
company. It was believed that by providing proper and adequate
facilities for garaging electric pleasure vehicles the use of passenger-
electrics in New York City would be greatly increased.

Electricity and the Home.


In emphasizing the important part which electricity plays in the
business of a great metropolis, the home should not be forgotten. It
is now possible, by means of electric appliances, practically to
eliminate all drudgery from housework. The use of many of these
domestic machines is familiar to all: vacuum cleaners, washing
machines, fans, and the more usual electric cooking devices. Within
the next decade, one looks to see a remarkable advance in this
direction. One anticipates the more extensive use of electric
refrigeration and other electric labor-saving devices, to the great
improvement of city homes, making them pleasanter and more
healthy as toilsome operations are done away with. And it must not
be forgotten that the city home, like the country home, is the
backbone of the well-being of the community. Electricity can have no
greater mission than improving, strengthening and upbuilding good
homes.
[283]

Electric Train Chart and Switch Control


Subway Construction
In the upper view the electric chart on the wall facing the
switch operator indicates the location of every train in the
New York subway system at all times. The lower view shows
typical subway construction for third rail train and surface
cars. The material used is reinforced concrete.

[284]
One Type of Electric Construction on Railroads
The system shown here is used upon the New York, New Haven and Hartford
Railroad. It consists of pairs of wire cables supported by bridges placed about 300
feet apart. Rigid triangles of iron pipe are secured to these cables and the trolley
wire attached to the triangles. The trolley wire is kept rigid and free from slack in
this manner.

Decreased Cost of Electricity.


Closely akin to this is another electrical development most pleasing to
consider. Years ago, electricity was considered the luxury of the rich.
Now electric light is coming to be shed on rich and poor alike. Little
by little the shops, factories and dwellings of more humble
inhabitants are provided with electricity, so that cleanliness, safety
and comfort are by no means confined even to the well-to-do or the
more comfortable homes.
One great factor in this change has been the decreasing cost of
electricity. Within the last decade, the cost of almost all necessities of
life has ascended with leaps and bounds, so that a dollar now,
expended in ordinary household goods, will purchase hardly more
than what thirty cents would in 1890. But all this while, the cost of
electricity has steadily decreased. With centralized generating plants,
improved machinery and better lamps, one dollar today will buy
eighteen times as much electric light as it would in 1884. With such
facts before us, it is fairly easy to predict the still further electrical
development of all important centers. There will be more and better
light in homes; there will be more and better light in offices and
factories, thus greatly lessening the chances for injury or eye-strain.
In all industry, great and small, laborious hand processes will be
replaced by safely operated electric machinery, while wider use of
electric labor-saving appliances will extend into the home.
Hospitals, by aid of electricity, will be able to increase still more their
splendid work for the relief of suffering, while cleaner and safer ways
of living will serve as a preventive of disease. One can easily say that
with increasing electrical development the country will come to be
still greater, a country where electricity shall provide for the safety
and well-being of all its people.

How is Die-Sinking Done?


Die-sinking is the art of preparing dies for stamping coins, buttons,
medallions, jewelry, fittings, etc. The steel for the manufacture of dies
is carefully selected, forged at a high heat into the rough die,
softened by careful annealing, and then handed over to the engraver.
After the engraver has worked out the design in intaglio the die is put
through the operation of hardening, after which, being cleaned and
polished, it is called a “matrix.” This is not, however, generally
employed in multiplying impressions, but is used for making a
“punch” or steel impression for relief. For this purpose another block
of steel of the same quality is selected, and, being carefully annealed
or softened, is compressed by proper machinery upon the matrix until
it receives the impression. When this process is complete the
impression is retouched by the engraver, and hardened and collared
like the matrix. Any number of dies may now be made from this
punch by impressing upon it plugs of soft steel.
The Story in the Making of a
[19]
Magazine

The printing of a few thousand copies of one of the great American


magazines would not be a difficult feat for any large first-class
printing plant. The putting of the pages into type and running them
through the modern job presses could easily be accomplished. But
when, instead of a few thousand copies, millions of copies of the
magazine are printed, and these millions are produced unfailingly,
week after week, month after month, in a quality of printing rivaling
the production of but a few thousand copies, then, indeed, is it
marvelous how results are attained.

One of the Scores of Presses on which the Inside Pages of “The


Saturday Evening Post” are Printed
Obviously, one of the first necessities towards such quantity
production is extra speed. This is secured to a certain degree by
feeding the paper into the presses from rolls instead of sheet by
sheet. But as the quality of the print must be retained, there is a limit
in this speeding beyond which it is not safe to go. Some other
method of increasing the production without lowering the quality of
the printed sheet must be resorted to—and this is duplication. By the
process of electrotyping, plates of metal duplicating exactly the
printing surface of the type and engravings in the original page, can
be made. By providing as many presses as may be needed, and by
supplying each press with duplicates, or electrotype plates as they
are called, the problem of vast quantity requirements has been
solved, so far as the actual printing is concerned.
But there are other factors to be considered. For example, the printed
sheets, as they come from the press, must be folded to the size of
the magazine. This is done in two ways. Machines which take the
sheets, one by one, from the completed pile, and fold them to the
required size, are used on some publications, while on others a
folding machine and a binding attachment are included as integral
parts of the press itself. The paper, as it comes from the printing
section of the press, is mechanically folded, cut apart, the previously-
printed cover sheet wrapped around it, and the whole stapled
together with wire stitches. Thus the white paper, which enters the
press from the roll in one long ribbon, is delivered at the other end of
the press printed, folded and bound up into complete magazines at
the rate of sixty each minute. Issues of a magazine of thirty-two,
forty-eight, or even more pages, are produced in this manner.
One of the Several Batteries of Presses Necessary to Print “The
Ladies’ Home Journal”

Many magazines, however, have more pages than this. Then it is


necessary to print on separate presses the various sections, or
signatures as they are called, which, when combined, will make up a
complete magazine. If only a few thousand were printed, these
signatures could be collected together by hand, and then fed into the
wire-stitching machine, also by hand. This method of collecting the
sections and binding them together was the one used until editions
became so large that mechanical methods became necessary.
Now, however, the various sections which go to make up the
magazine are piled in certain troughs of a binding machine, which,
with seeming human intelligence, clasps one copy of each section in
turn, and combining them with a copy of the cover sheet, conducts
them all, properly collated, into the wire-stitching device, from which
they are ejected into orderly piles. Some magazines are bound
together in a different manner, however, and are not stitched with
wire, but have the inside pages and the cover glued together, and an
ingenious binding machine has been perfected which does this
automatically.
[288]

A Group of Folding Machines which Automatically Grasp the Flat Sheet and Fold it up
to the Size of the Magazine

Another marvel of the periodical of our day is the printing of some of


the pages in the full colors of the original paintings. To get this result,
it is necessary to print the sheet in four colors and to have each
printing in exactly the correct spot on the sheet (a variation of only a
hundredth of an inch being detrimental). The process would normally
be quite slow—too slow, in fact, for the tremendous quantities
necessary for the large editions of the modern magazine. Both of
these objections have been overcome, however, by arranging four
small cylinders, each printing its designated color—yellow, red, blue
or black—so that as the sheet of paper travels around a larger
cylinder it is brought into contact with the four printing cylinders in
rapid succession.
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!

textbookfull.com

You might also like