bash scripting
Bash recipes
Leverage ShellCheck.net and the VS Code Addin
bash scripting
Proper escaping - Everything is a string
Accessing values
everything-is-a-string.sh
Executing a command
run-a-command.sh
Defining variables
Creating and accessing an array in bash
array.sh
Creating and accessing a hashmap / dict bash
Determine the directory of the script
show:dir.sh
results in
Span a command across multiple lines
Use a baskslash (\
) at the end of the line (no additional whitespace), and preferably indent the next line:
multi-line.sh
Lambda-style functions in bash
health-probe.sh
results in
Creating a text file
The cat > x <<-EOF ... EOF
syntax allows to create a file in the local directory. Please not that the lines 6 and 7 below (the content) are prefixed with a tabstop (), which does not show up in the actual text file.
base64-encode a text
The command base64 --wrap=0
converts input into a long base64-encoded string without line breaks.
Bash history
Put the following lines in ~/.inputrc
:
Last updated