Useful Links
Computer Science
Programming
By Language
Bash/Shell Scripting
1. Introduction to the Shell and Scripting
2. Core Scripting Concepts
3. Control Flow and Logic
4. Working with Data
5. Functions and Modularity
6. Advanced Scripting Techniques
7. Debugging and Best Practices
Core Scripting Concepts
Variables
Defining and Assigning Variables
Basic Assignment Syntax
No Spaces Around Equals Sign
Case Sensitivity
Naming Conventions
Allowed Characters
Letters
Numbers
Underscores
Starting with Letter or Underscore
Best Practices
Descriptive Names
Consistent Naming Style
Avoiding Reserved Words
Accessing Variable Values
Using Dollar Sign ($)
Using Curly Braces (${VAR})
When Braces Are Required
Environment Variables
Definition and Purpose
Exporting Variables (export)
Common Environment Variables
PATH
HOME
USER
SHELL
PWD
OLDPWD
Viewing Environment
env Command
printenv Command
set Command
Special Shell Variables
Exit Status ($?)
Process ID ($$)
Number of Arguments ($#)
All Arguments as Array ($@)
All Arguments as String ($*)
Script Name ($0)
Positional Parameters ($1, $2, ...)
Last Background Process ID ($!)
Variable Scope
Local Variables
Global Variables
Subshell Variables
Readonly Variables
readonly Command
declare -r
Unsetting Variables
unset Command
Quoting and Escaping
The Need for Quoting
Preventing Word Splitting
Preventing Globbing
Preserving Whitespace
Double Quotes
Variable Expansion
Command Substitution
Arithmetic Expansion
Preserving Most Special Characters
Single Quotes
Literal Strings
No Expansions
Including Single Quotes in Strings
Backslash Escaping
Escaping Special Characters
Escaping Newlines
Common Escape Sequences
ANSI-C Quoting ($'...')
Escape Sequences
Unicode Characters
Input, Output, and Redirection
Standard Streams
Standard Input (stdin, 0)
Standard Output (stdout, 1)
Standard Error (stderr, 2)
Output Redirection
Overwrite Redirection (>)
Append Redirection (>>)
Redirecting to Files
Redirecting to /dev/null
Input Redirection
Reading from Files (<)
Reading from Standard Input
Error Redirection
Redirecting stderr (2>)
Appending stderr (2>>)
Combining stdout and stderr (&>)
Redirecting stderr to stdout (2>&1)
Here Documents
Basic Syntax (<<)
Delimiter Selection
Quoting Delimiters
Indented Here Documents (<<-)
Here Strings
Basic Syntax (<<<)
Use Cases
Pipes
Basic Pipe Operator (|)
Chaining Multiple Commands
Named Pipes (FIFOs)
Process Substitution
Input Process Substitution (<())
Output Process Substitution (>())
Command Substitution
Backticks (Legacy Method)
Basic Syntax
Limitations
Dollar-Parentheses (Modern Method)
Basic Syntax ($())
Advantages over Backticks
Nesting Command Substitutions
Capturing Command Output
Error Handling in Command Substitution
Arithmetic Operations
Integer Arithmetic
let Command
Double Parentheses ((...))
expr Command
Arithmetic Expansion $((...))
Arithmetic Operators
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Modulo (%)
Exponentiation (**)
Comparison Operators
Equal (==)
Not Equal (!=)
Less Than (<)
Greater Than (>)
Less Than or Equal (<=)
Greater Than or Equal (>=)
Floating-Point Arithmetic
bc Calculator
awk for Calculations
Increment and Decrement
Pre-increment (++var)
Post-increment (var++)
Pre-decrement (--var)
Post-decrement (var--)
Previous
1. Introduction to the Shell and Scripting
Go to top
Next
3. Control Flow and Logic