Bash Script
Bash Script
Introduction
Example
Variables
Generally quote your variables unless they contain wildcards to expand or command fragments.
String quotes
Shell execution
Conditional execution
Functions
Conditionals
Strict mode
Brace expansion
Same as
Same as
Same as
Same as
Parameter expansions
Basics
Substitution
Remove suffix
Remove prefix
Replace all
Replace suffix
Replace prefix
Comments
Substrings
Length
Length of
Manipulation
Default values
, or if unset (or null)
Omitting the removes the (non)nullity checks, e.g. expands to if unset otherwise .
Loops
Ranges
Forever
Functions
Defining functions
Returning values
Raising errors
Arguments
Number of arguments
First argument
Note: and must be quoted in order to perform as described. Otherwise, they do exactly the same
thing (arguments as separate strings).
Conditionals
Conditions
Note that is actually a command/program that returns either (true) or (false). Any program that
obeys the same logic (like all base utils, such as or ) can be used as condition, see
examples.
Empty string
Equal
Not Equal
Equal
Not equal
Less than
Greater than
Regexp
Numeric conditions
More conditions
If OPTIONNAME is enabled
! EXPR Not
And
Or
File conditions
Exists
Readable
Symlink
Directory
Writable
File
Executable
Same files
Example
$B
Arrays
Defining arrays
Working with arrays
Operations
Iteration
Dictionaries
Defining
Declares as a Dictionary object (aka associative array).
Iteration
Options
Options
Glob options
History
Commands
Show history
Expansions
Slices
Expand only th token from most recent command (command is ; first argument is )
Numeric calculations
Subshells
Redirection
"ERROR:
Case/switch
Source relative
printf
Transform strings
Delete characters
Truncates
All digits
All whitespace
All letters
Example
Directory of script
Getting options
Heredoc
Reading input
Special variables
Exit status of last task
PID of shell
s.
Go to previous directory
Grep check