Bash and shell script programming is central to using Linux, but it has many peculiar properties that are hard to understand and unfamiliar to many programmers, with a lot of misleading and even risky information online. Bash Quick Start Guide tackles these problems head on, and shows you the best p
Bash Quick Start Guide: Get up and running with shell scripting with Bash
β Scribed by Tom Ryder
- Publisher
- Packt Publishing
- Year
- 2018
- Tongue
- English
- Leaves
- 178
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Learn how to write shell script effectively with Bash, to quickly and easily write powerful scripts to manage processes, automate tasks, and to redirect and filter program input and output in useful and novel ways.
Key Features
- Demystify the Bash command line
- Write shell scripts safely and effectively
- Speed up and automate your daily work
Book Description
Bash and shell script programming is central to using Linux, but it has many peculiar properties that are hard to understand and unfamiliar to many programmers, with a lot of misleading and even risky information online. Bash Quick Start Guide tackles these problems head on, and shows you the best practices of shell script programming.
This book teaches effective shell script programming with Bash, and is ideal for people who may have used its command line but never really learned it in depth. This book will show you how even simple programming constructs in the shell can speed up and automate any kind of daily command-line work.
For people who need to use the command line regularly in their daily work, this book provides practical advice for using the command-line shell beyond merely typing or copy-pasting commands into the shell. Readers will learn techniques suitable for automating processes and controlling processes, on both servers and workstations, whether for single command lines or long and complex scripts. The book even includes information on configuring your own shell environment to suit your workflow, and provides a running start for interpreting Bash scripts written by others.
What you will learn
- Understand where the Bash shell fits in the system administration and programming worlds
- Use the interactive Bash command line effectively
- Get to grips with the structure of a Bash command line
- Master pattern-matching and transforming text with Bash
- Filter and redirect program input and output
- Write shell scripts safely and effectively
Who this book is for
People who use the command line on Unix and Linux servers already, but don't write primarily in Bash. This book is ideal for people who've been using a scripting language such as Python, JavaScript or PHP, and would like to understand and use Bash more effectively.
Table of Contents
- What is Bash?
- Bash Command Structure
- Essential Commands
- Input, Output, and Redirection
- Variables and Patterns
- Loops and Conditionals
- Scripts, Functions, and Aliases
- Best Practices
β¦ Table of Contents
Cover
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Table of Contents
Preface
Chapter 1: What is Bash?
What Bash is and is not
Getting Bash
Checking Bash is running
Switching the login shell to Bash
Identifying the Bash version number
Upgrading Bash on macOS X
Understanding Bash features
POSIX shell script features
Bash-specific features
Do I need Bash?
Choosing when to apply Bash
Choosing when to avoid Bash
Getting help with Bash
Summary
Chapter 2: Bash Command Structure
Using Bash interactively
Interactive key bindings
Simple commands
Shell metacharacters
Quoting
Escaping
Single quotes
Double quotes
Quote concatenation
Running commands in sequence
Exit values
Stopping a command list on error
Running a command in the background
Summary
Chapter 3: Essential Commands
Distinguishing command types
Essential Bash builtin commands
The type command
The echo command
The printf command
The pwd command
Tilde paths
The cd command
Changing the directory in scripts
The set command
The declare command
The test, [, and [[ commands
Essential system commands
The ls command
Getting filename lists without ls
The mv command
The cp command
The rm and rmdir commands
The grep command
The cut command
The wc command
Getting file sizes with wc or du
The find command
Executing commands for each result
A note about find and xargs
The sort and uniq commands
Summary
Chapter 4: Input, Output, and Redirection
Redirecting output
Redirection paths
Avoiding overwrites
Appending to files
Understanding created file permissions
Choosing permissions for created files
Redirecting errors
Combining errors with output
Blocking errors completely
Sending output to more than one place
Redirecting input
Using a long string as input with here-documents
Using pipes
Adding file contents to a stream
Piping output from multiple programs
Filtering programs
The sed stream editor
The AWK programming language
Summary
Chapter 5: Variables and Patterns
Using variables
Listing variables
Naming variables
Variable name case
Clearing variables
Environment variables
Calling programs with environment variables
Expanding variables
Reading a value into a variable
Getting command output in variables
Parameter expansion forms
Specifying default values
String chopping
Extracting substrings
Getting string length
Substituting strings
Changing case
Combining parameter expansion forms
Doing math in Bash
Fixed or floating-point arithmetic
Using globs
Configuring globbing behavior
Including dot files, but excluding dot and dot-dot
Expanding to nothing
Case-insensitive globbing
Extended globbing
Using arrays
Glob expansion in arrays
Associative arrays
Summary
Chapter 6: Loops and Conditionals
Using the if keyword
Using the test command
Using the [ command
Using the [[ keyword
Arithmetic conditions
Switching with the case keyword
Looping over shell words with for
Skipping an iteration
Ending the loop
Misuse of for loops
Using Bash's C-style for loops
Using while loops
Infinite loops
Reading data line by line
Field splitting
Saving fields into arrays
Choosing the splitting character
Disabling whitespace trimming
Reading process output
Avoiding subshell problems
Avoiding input problems with ssh
Summary
Chapter 7: Scripts, Functions, and Aliases
Aliases
Defining new aliases
Understanding shortcomings with aliases
Functions
Defining functions
Passing arguments to functions
Using --Β to separate options from filenames
Getting all the arguments
Returning values from functions
Understanding function input and output
Function scope
Reloading functions at shell startup
Scripts
Scripting methods
Writing a shebang script
Finding scripts with $PATH
System bindir
User bindir
Arguments to scripts
Understanding sh vs bash
Using env
Choosing between functions and scripts
Using functions in scripts
Summary
Chapter 8: Best Practices
Quoting correctly
When you don't want quotes
Handling filenames starting with dashes
Separating output and diagnostics
Keeping scripts brief and simple
Keeping scripts flexible
Respecting and applying the user's configuration
Allowing scripts to run without user input
Limiting the scope of shell state changes
Avoiding path anti-patterns
Avoiding Bash for untrusted user input
Documenting scripts
Writing comments
Providing help output
Writing manual pages
Using temporary files cleanly
Cleaning up after a script
Tools to check shell scripts for problems
Summary
Other Books You May Enjoy
Index
β¦ Subjects
COM088000 - COMPUTERS / System Administration / General, COM011000 - COMPUTERS / Systems Architecture / General, COM088010 - COMPUTERS / System Administration / Linux & UNIX Administration
π SIMILAR VOLUMES
Von den Autoren des erfolgreichsten veganen Kochbuchs aller Zeiten! FΓΌr alle, die aufregend-innovatives und rein pflanzliches Essen lieben, ist das neue Kochbuch der BOSH-Jungs perfekt! Henry Firth und Ian Theasby, Betreiber der grΓΆΓten veganen Plattform BOSH, prΓ€sentieren in ihrem zweiten Kochbuch
<p><b>Your step by step guide with easy to follow instructions for navigating Drupal 8</b></p>Key Features<li>Build a great Drupal website easily</li><li>How to structure, create and maintain different types of content</li><li>Design roles for secure editing of your site</li>Book Description<p>Drupa
A concise walk-through of CentOS 7, starting from installation to securing it's environment. Key Features No previous Linux environment experience needed for reading this book Get comfortable with a popular and stable Red Hat Enterprise Linux distribution Most of the command line based concepts are
<p><span>Your step by step guide with easy to follow instructions for navigating Drupal 8</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Build a great Drupal website easily</span></span></li><li><span><span>How to structure, create and maintain different types of content</span></spa