Bash
Shell scripting commands for automation, text processing, conditionals, loops, and writing maintainable Bash scripts.
100 commands
Browse by Topic
Check Bash version
Display the current Bash shell version information
Install latest Bash (macOS)
Install the latest version of Bash using Homebrew on macOS
Check current shell
Display the path of the current default login shell
Shebang line
Standard bash script header.
Make executable
Make script executable.
Debug mode
Run script in debug mode.
Exit on error
Exit immediately if command fails.
Error on undefined vars
Error on undefined variables.
Pipe fail mode
Fail on pipe errors.
Strict mode
Enable all safety options.
Debug with line numbers
Debug with source file and line info.
Syntax check only
Check syntax without executing.
Get script directory
Get absolute path of script directory.
Source another script
Include another script file.
Exit trap
Run cleanup function on exit.
Error trap
Handle errors with line number.
Signal trap
Handle interrupt and terminate signals.
Remove trap
Remove a previously set trap.
Set variable
Assign value to variable.
Export variable
Export variable to environment.
Default value
Use default if variable unset.
Assign default
Assign default if unset and return it.
Error if unset
Error if variable unset.
Read-only variable
Create read-only variable.
Unset variable
Remove variable definition.
Command substitution
Capture command output in variable.
Arithmetic expansion
Perform arithmetic calculation.
Positional parameters
Access script arguments.
Number of arguments
Get number of positional parameters.
Last exit status
Get exit status of last command.
Current PID
Get process ID of current shell.
Background PID
Get PID of last background job.
Range loop
Loop through number range.
C-style for loop
Loop with counter variable.
File loop
Loop through files.
Read file lines
Loop through file lines safely.
Infinite loop
Run infinite loop.
Until loop
Loop until condition is true.
Loop with index
Loop with array indices.
Break loop
Exit loop early with break.
Continue loop
Skip iteration with continue.
Process substitution
Read from command output.
Loop with step
Loop with custom step value.
Define function
Define a function.
Function shorthand
Define function without keyword.
Function with args
Function with positional arguments.
Local variable
Declare local variable in function.
Return value
Return exit status from function.
Capture function output
Capture function output to variable.
All function args
Iterate over all function arguments.
Check function exists
Call function only if it exists.
Declare array
Create indexed array.
Access element
Get element by index.
All elements
Get all array elements.
Array length
Get number of elements.
Array indices
Get all array indices.
Append to array
Add element to end of array.
Array slice
Get subset of array (offset:length).
Delete element
Remove element at index.
Associative array
Create key-value associative array.
Associative keys
Get all keys of associative array.
Array from command
Populate array from command output.
Safe array from lines
Read file lines into array safely.
Join array
Join array elements with delimiter.
Last element
Get last array element (Bash 4.2+).
String length
Get length of string.
Substring
Extract substring (offset:length).
Substring from end
Get last N characters.
Replace first
Replace first occurrence.
Replace all
Replace all occurrences.
Remove prefix
Remove shortest prefix match.
Remove prefix greedy
Remove longest prefix (basename).
Remove suffix
Remove shortest suffix match.
Remove suffix greedy
Remove longest suffix (remove extension).
Uppercase
Convert to uppercase (Bash 4+).
Lowercase
Convert to lowercase (Bash 4+).
Capitalize first
Capitalize first character (Bash 4+).
Replace at start
Replace if at beginning.
Replace at end
Replace if at end.
Discussion
Loading comments...