Bash
Browse all articles, tutorials, and guides about Bash
About Bash
Explore Bash scripting to automate everyday tasks. Learn command-line techniques, shell utilities, and tips for building robust scripts.
Posts
What Does 'set -e' Mean in a Bash Script?
Learn what 'set -e' does in Bash scripts, why it's useful for error handling, and when you might want to use or avoid it. Includes practical examples and caveats.
How to Sleep for Milliseconds in Bash and Linux
Learn how to pause script execution for fractions of a second using sleep, usleep, and other methods for precise timing in Bash scripts and command-line operations.
How to Redirect All Output to a File in Bash
Learn how to redirect stdout and stderr to files in Bash, capture both standard output and errors together, and understand the different redirection operators.
What Does set -e Mean in a Bash Script?
The set -e command in Bash causes your script to exit immediately when any command fails. Learn when to use it, how it works, and common pitfalls to avoid.
How to Check if a Variable is Set in Bash
Learn multiple methods to check if variables are set, unset, empty, or have specific values in Bash scripts with practical examples and best practices.
How to Convert Strings to Lowercase in Bash
Discover multiple methods to convert strings to lowercase in Bash scripts, from modern parameter expansion to traditional command-line tools, with examples for different use cases and shell compatibility.
How to Check if a String Contains a Substring in Bash
Learn multiple methods to check for substring presence in Bash, including pattern matching, case-insensitive searches, and practical examples for string validation.
How to Concatenate String Variables in Bash
Learn multiple ways to combine string variables in Bash scripts, from simple concatenation to complex string operations with practical examples.
How to Redirect Output to Both a File and stdout in Bash
Discover how to use the tee command and other techniques to send command output to both a file and the terminal simultaneously, useful for logging while monitoring script execution.
How to Get the Current Time in Seconds Since the Epoch in Bash on Linux
Learn how to get Unix timestamps in Bash for logging, benchmarking, and time calculations. Includes examples of converting timestamps, measuring elapsed time, and practical use cases.
Understanding the Difference Between sh and Bash
Discover the key differences between sh and Bash shells, including feature compatibility, portability considerations, and when to use each one in your shell scripts and system administration tasks.
How to Set a Variable to the Output of a Command in Bash
Learn multiple methods to capture command output in Bash variables using command substitution, including best practices and error handling techniques.
How Does cat << EOF Work in Bash?
Understand heredocs in Bash - the << EOF syntax that lets you write multi-line strings, create files with embedded content, and pass complex input to commands.
How to Check for Input Arguments in Bash Shell Scripts
Learn different methods to validate command-line arguments in your Bash scripts, from simple existence checks to handling optional and required parameters with practical examples.
How to Prompt for Yes/No/Cancel Input in a Linux Shell Script
Learn different techniques for creating interactive prompts in your shell scripts, from simple yes/no confirmations to three-way choices with proper input validation and user-friendly interfaces.
How to Echo Output to stderr in Bash
Learn different methods to send error messages to stderr in Bash scripts, understand why separating error output from standard output matters, and discover best practices for script logging and debugging.
How to Create a Bash Alias That Accepts Parameters
Learn how to create flexible Bash aliases that accept arguments using functions, from simple one-liners to complex commands with multiple parameters and options.
How to Format Dates as YYYY-MM-DD in Shell Scripts
Learn how to format dates in shell scripts using the date command, including YYYY-MM-DD format and other common date patterns for logging, file naming, and timestamp generation.
How to Check if a File Does Not Exist in Bash
Learn various methods to test for file non-existence in Bash scripts, including proper error handling, permission checks, and practical automation examples.
How to Extract Filename and Extension in Bash
Learn multiple methods to extract filenames, extensions, and directory paths from file paths in Bash using parameter expansion and basename commands.
What Is the Preferred Bash Shebang?
Learn which shebang line to use for Bash scripts, the differences between common options, and how to write portable scripts that work across different Unix-like systems.
How to Split a String on a Delimiter in Bash
Learn multiple methods to split strings using delimiters in Bash, including IFS, parameter expansion, and array techniques with practical examples.
How to Redirect and Append Both stdout and stderr to a File in Bash
Learn different methods to capture both standard output and error streams in Bash, including appending to files and separating streams for better logging.
How to Check if a Program Exists from a Bash Script
Learn multiple reliable methods to check if a command or program is available on your system from within Bash scripts, including using which, command, and type.
What Does "2>&1" Mean in Linux and Bash?
Learn what the 2>&1 redirection operator means in Linux commands, how it works with standard output and error streams, and when to use it effectively.
How to Count Lines of Code in a Directory Recursively
Discover multiple methods to count source code lines across entire directory trees, including filtering by file types and excluding specific directories.
How to Get the Directory Where a Bash Script is Located
Learn multiple reliable methods to determine the directory path of your Bash script from within the script itself, including handling symbolic links and edge cases.
How to Iterate Over a Range of Numbers in Bash Using Variables
Learn different methods to loop through number ranges defined by variables in Bash, from simple for loops to advanced sequence generation techniques.
How to Reload .bashrc Settings Without Logging Out
Need to apply changes to your .bashrc file immediately? Learn multiple methods to reload your Bash configuration without restarting your terminal session.
Looping Through File Content Line by Line in Bash
Learn multiple techniques to read and process file content line by line in Bash scripts, including handling special characters and preserving whitespace.