Linux Shell Scripting Essentials
eBook - ePub

Linux Shell Scripting Essentials

Sinny Kumari

Condividi libro
  1. 282 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Linux Shell Scripting Essentials

Sinny Kumari

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

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.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Linux Shell Scripting Essentials è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Linux Shell Scripting Essentials di Sinny Kumari in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Operating Systems. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2015
ISBN
9781785284441
Edizione
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...

Indice dei contenuti