A repository for showing examples of shell scripts.
The aim is to use examples to demonstrate how shells behave and squash some assumptions.
It's also a repository used for collecting various shell related tooling.
A list of things still to try and investigate TODO.md
NOTE: This repo has switched to conventional commits. It requires pre-commit
and commitizen
to help with controlling this.
# install pre-commmit (prerequisite for commitizen)
brew install pre-commit
brew install commitizen
# conventional commits extension
code --install-extension vivaxy.vscode-conventional-commits
# install hooks
pre-commit install --hook-type commit-msg --hook-type pre-push
- Shell Examples and Demos
- Conventional Commits
- Contents
- 1οΈβ£ Prequisites
- βShell Help
- βΉοΈ Useful commands
- 00 - Cheatsheet
- 01 - Simple argument parsing
- 02 - Functions as jobs
- 03 - Pipe filters
- 04 - Trap handlers
- 05 - Strings
- 06 - Restricted bash shell
- 07 - OS Detection
- 08 - Paths Testing
- 09 - Debian packaging
- 10 - Functions
- 11 - Man pages
- 12 - CSV parsing
- 13 - Bats
- 14 - CI Env Overrides
- 15 - Screen Control
- 16 - Globbing
- 17 - Logger
- 18 - Bats Mocking
- 19 - Timing Operations
- 20 - GPG examples
- 21 - Webserver
- 22 - SystemD Service
- 23 - Whiptail Selector
- 24 - Finding files
- 25 - Autocompletions
- 26 - Cron
- 27 - JournalCtl
- 28 - Old Skool Ascii Banner
- 29 - Imagemagick
- 30 - User input
- 31 - Dependency checking
- 32 - JQ
- 33 - AWSCLI
- 35 - APT and DPKG
- 36 - Git Querying and Examples
- 37 - Guid generation
- 38 - Mapping inputs to outputs
- 42 - yq and yaml
- 43 - AWK
- 44 - Looping over indexed envvars
- 46 - stdin, stdout and stderr redirection
- 47 - FFMPEG
- 48 - SED
- 49 - brew
- 50 - tmux and screen
- 51 - grep and regex
- 52 - xml
- 53 - syncing files
- 54 - date handling
- 55 - vim setup
- 56 - options handling
- 58 - gstreamer
- 59 - monitoring folders
- 60 - creating HLS streams from segments
- 61 - curl
- 62 - binary files
- 63 - md5
- 64 - calculations
- 65 - pipes
- 66 - generating and renaming files
- 68 - difftools
- 69 - dotsourcing
- 70 - xargs
- 71 - disk usage
- 72 - line endings
- 73 - creating archives
- 74 - envelope encryption
- 75 - just
- 76 - links
- 78 - dns
- 79 - hurl
- 80 - parallel
- 81 - gpu
- 82 - clipboard
- π Resources
- Shellchecking
- Pre-commit hook (shellcheck)
- Updating RELEASE_NOTES
-
Install shellcheck
-
Install vscode extension for shellcheck
code --install-extension timonwong.shellcheck
Depending on the shell you are running the help for builtins is different
bash
man bash
help <builtin>
info <command>
zsh
man zsh
man zshbuiltins
# list all aliases
alias
# list all functions (zsh)
print -l ${(ok)functions}
Cheatsheets are a great way to quickly get an answer to your question.
Steps README.md
Demonstrates how to build a script with simple argument parsing.
Steps README.md
Demonstrates how to initiate a function as a job.
Steps README.md
Demonstrates how read from stdin stream and process it.
Steps README.md
Demonstrate trap handlers functionality
Steps README.md
Demonstrate some examples of string manipulation and variables
Steps README.md
Demonstrate a restricted bash shell
Steps README.md
Demonstrate how to detect the OS type in script to change parameters to commands.
Steps README.md
Demonstrates ways of manipulating paths
Steps README.md
Demonstrates building a debian package repository
Steps README.md
Demonstrates different types of techniques for using functions
Steps README.md
Demonstrate how to create a manpage.
Steps README.md
Demonstrate how to parse and work with CSV files.
Steps README.md
Demonstrate how to use bats for testing
Steps README.md
Demonstrate a way to produce ENV overrides in a CI pipeline
Steps README.md
Demonstrates how to control the termninal screen output
Steps README.md
Demonstrates techniques for globbing and operating on sets of files
Steps README.md
Demonstrates how to implement a logger for scripts
Steps README.md
Demonstrates how to test using mocks with bats.
Steps README.md
Demonstrate how to time operations in the shell to help with optimisation.
Steps README.md
Demonstrate how to use GPG to encrypt and decrpyt files.
Steps README.md
Demonstrate how to set up a webserver in bash
Steps README.md
Demonstrate how to create a systemd service.
Steps README.md
Demonstrate how to use whiptail for file selection.
Steps README.md
A few examples on using shell to find files
Steps README.md
Demonstrate how to write autocomplete scripts
Steps README.md
Demonstrate how to setup a cronjob
Steps README.md
Demonstrate how to use journalctl to discover logs
Steps README.md
An old skool banner printer.
Steps README.md
Examples of using imagemagick to process images.
Steps README.md
Demonstrate how to use user input in scripts
Steps README.md
Demonstrates how to check dependencies exist before a script runs
Steps README.md
Demonstrates some examples of using jq to process json files
Steps README.md
Demonstrates using awscli to query resources in an AWS account.
Steps README.md
Demonstrate examples of working with APT and DPKG
Steps README.md
Demonstrates some examples of using git
queries and tools
Steps README.md
Demonstrates techniques for generating unique ids in scripts.
Steps README.md
Demonstrate how to map an input to an output Steps README.md
Demonstrates some examples of using yq
to process yaml files
Steps README.md
Demonstrates techniques for using awk to process files.
Steps README.md
Demonstrates techniques processing environment variables.
Steps README.md
Demonstrate and work through some stdout and stderr redirection
Steps README.md
Demonstrate how to use ffmpeg to perform different types of encodings.
Steps README.md
Demonstrates techniques for using sed to process files.
Steps README.md
Demonstrate how to create a brew
package.
Steps README.md
Demonstrate some terminal multiplexors like tmux
and screen
Steps README.md
Demonstrates examples of how to use grep and regex.
Steps README.md
Demonstrate how to handle Xml in shell scripts.
Steps README.md
Demonstrate some examples syncing directories
Steps README.md
Demonstrate date handling in shell.
Steps README.md
Demonstrates configuring a container for vim
Steps README.md
Demonstrate how to use shell options in shell scripts.
Steps README.md
Demonstrate some basic gstreamer
examples
Steps README.md
Demonstrate how to monitor a folder for changes using inotify
or watchman
.
Steps README.md
Demonstrates building a hls from individual segments of wav files.
Steps README.md
Demonstrate some common examples with curl
Steps README.md
Working with binary files in shell.
Steps README.md
Demonstrate how to id files using md5
and md5sum
Steps README.md
Demonstrate some way of performing calculations in shell and scripts.
Steps README.md
Demonstrate how to work with anonymous and named pipes.
Steps README.md
Demonstrate techniques for generating and renaming files.
Steps README.md
Example textual diffing tools.
Steps README.md
Demonstrate how to use dot-sourcing.
Steps README.md
Demonstrate basic behaviour with xargs
.
Steps README.md
Demonstrate some examples of calculating disk usage.
Steps README.md
Demonstrate some examples of working with line-endings differences.
Steps README.md
Demonstrate how to create archive files.
Steps README.md
Demonstrate how to perform envelope encryption.
Steps README.md
Demonstrate how just
can be used like package.json scripts.
Steps README.md
Demonstrate symbolic and hard links.
Steps README.md
Examples for working with DNS.
Steps README.md
Use hurl to test an API.
Steps README.md
Demonstrate how to use parallel
Steps README.md
Demonstrate how to interrogate and use GPU on OS platforms.
Steps README.md
Examples of using clipboard in the shell
Steps README.md
find . -iname '*.sh' -exec shellcheck {} \;
Install the pre-commit hook.
# hardlink the script
ln ./hooks/pre-commit .git/hooks/pre-commit
docker run -it --rm -v $(pwd):/repo chrisguest/turn --action=create --type=release --includenext --tags