Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Title Page
Copyright and Credits
Bash Quick Start Guide
Dedication
Packt Upsell
Why subscribe?
Packt.com
Contributors
About the author
About the reviewers
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
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
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
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
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
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
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
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
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
Leave a review - let other readers know what you think
← Prev
Back
Next →
← Prev
Back
Next →