Linux Shell Scripting Essentials
eBook - ePub

Linux Shell Scripting Essentials

Sinny Kumari

Share book
  1. 282 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Linux Shell Scripting Essentials

Sinny Kumari

Book details
Book preview
Table of contents
Citations

About This Book

Learn shell scripting to solve complex shell-related problems and to efficiently automate your day-to-day tasks

About This Book

  • Familiarize yourself with the terminal by learning about powerful shell features
  • Automate tasks by writing shell scripts for repetitive work
  • Packed with easy-to-follow, hands-on examples to help you write any type of shell script with confidence

Who This Book Is For

This book is aimed at administrators and those who have a basic knowledge of shell scripting and who want to learn how to get the most out of writing shell scripts.

What You Will Learn

  • Write effective shell scripts easily
  • Perform search operations and manipulate large text data with a single shell command
  • Modularize reusable shell scripts by creating shell libraries
  • Redirect input, output, and errors of a command or script execution to other streams
  • Debug code with different shell debugging techniques to make your scripts bug-free
  • Manage processes, along with the environment variables needed to execute them properly
  • Execute and embed other languages in your scripts
  • Manage creation, deletion, and search operations in files

In Detail

Shell scripting is a quick method to prototype complex applications or problems. Shell scripts are a collection of commands to automate tasks, usually those for which the user has a repeated need, when working on Linux-based systems. Using simple commands or a combination of them in a shell can solve complex problems easily.

This book starts with the basics, including essential commands that can be executed on Linux systems to perform tasks within a few nanoseconds. You'll learn to use outputs from commands and transform them to show the data you require. Discover how to write shell scripts easily, execute script files, debug, and handle errors.

Next, you'll explore environment variables in shell programming and learn how to customize them and add a new environment. Finally, the book walks you through processes and how these interact with your shell scripts, along with how to use scripts to automate tasks and how to embed other languages and execute them.

Style and approach

This book is a pragmatic guide to writing efficient shell programs, complete with hands-on examples and tips.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Linux Shell Scripting Essentials an online PDF/ePUB?
Yes, you can access Linux Shell Scripting Essentials by Sinny Kumari in PDF and/or ePUB format, as well as other popular books in Computer Science & Operating Systems. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785284441
Edition
1

Linux Shell Scripting Essentials


Table of Contents

Linux Shell Scripting Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. The Beginning of the Scripting Journey
Hello World in shell
Interacting with shell
Let's make it scripted
Define variables of choice
Nomenclature
Assigning a value
Accessing a value
Constant variables
Reading variables from a user input
Builtin shell variables
Operators
The assignment operator
Arithmetic operators
Logical operators
Comparison operators
Shell expansions
~ (Tilde)
* (Asterisk)
? (Question mark)
[ ] (Square brackets)
{ } (Curly brackets)
Construct commands using eval
Make bash behave using set
Exit on the first failure
Enabling/disabling symbolic link's resolution path
Setting/unsetting variables
Summary
2. Getting Hands-on with I/O, Redirection Pipes, and Filters
Standard I/O and error streams
File descriptors
Redirecting the standard I/O and error streams
Redirecting standard output
Redirecting standard input
Redirecting standard errors
Multiple redirection
Pipe and pipelines ā€“ connecting commands
Pipe
Pipeline
Regular expressions
Regular expression metacharacters
Character ranges and classes
Character ranges
Matching dates in mm-dd-yyyy format
Matching a valid month
Matching a valid day
Matching the valid year in a date
Combining valid months, days, and years regex to form valid dates
Regex for a valid shell variable
Filtering an output using grep
Syntax
Looking for a pattern in a file
Looking for a pattern in multiple files
A few more grep usages
Searching in a binary file
Searching in a directory
Excluding files/directories from a search
Display a filename with a matching pattern
Matching an exact word
Editing output using sed
String substitution using s
Multiple substitutions
Duplicating a stream using tee
Writing an output to stdout and appending to a file
Sending an output to multiple commands
Sorting and finding unique text
Sorting an input text
Sorting a single file
Redirecting output to sort
Filtering unique elements
Unique elements in a file
Character-based translation using tr
Deleting input characters
Squeezing to a single occurrence
Inverting a character set to be translated
Filtering based on linesā€”head and tail
Printing lines using head
Printing the first few lines
Printing the first few bytes
Printing lines using tail
Checking log entries
Finding any line in a file
The Cut-based selection
Cutting across columns
Text selection in files
Summary
3. Effective Script Writing
Exiting from scripts and exit codes
Exit codes
Exit codes with a special meaning
Script with exit codes
Testing expressions with a test
File checks
Arithmetic checks
String checks
Expression checks
Using conditional statements with if and else
Simple if and else
The if, elif, and else statements
Nested if
Indexed arrays and associative arrays
Indexed arrays
Array declaration and value assignment
Operations on arrays
The associative array
The declaration and value assignment
Operations on arrays
Looping around with for
Simple iteration
Iterating over a command output
Specifying a range to the for loop
Small and sweet for loop
The select, while, and until loops
Loop using select
The while loop
The until loop
Switch to my choice
Passing stdout as a parameter using xargs
Basic operations with xargs
Using xargs to find a file with the maximum size
Archiving files with a given pattern
Using funct...

Table of contents