Skip to content

chrisguest75/shell_examples

Folders and files

NameName
Last commit message
Last commit date
Sep 11, 2024
May 10, 2022
Dec 27, 2024
Dec 26, 2024
Jan 7, 2024
Mar 3, 2022
Nov 4, 2022
Dec 2, 2022
Oct 16, 2022
Oct 25, 2023
Dec 23, 2023
Jan 7, 2024
Oct 25, 2023
Apr 30, 2020
Nov 18, 2023
Mar 7, 2025
Feb 28, 2023
May 15, 2021
Apr 11, 2020
Dec 26, 2024
Apr 26, 2020
Feb 28, 2023
Nov 4, 2022
Nov 19, 2022
Jul 25, 2022
Jul 25, 2022
Jul 25, 2022
Jan 10, 2025
Jul 25, 2022
Jan 27, 2021
Jan 2, 2024
Sep 22, 2023
Dec 22, 2024
Sep 14, 2021
Oct 16, 2022
Dec 18, 2023
Feb 19, 2025
Dec 21, 2023
Dec 4, 2024
Feb 15, 2025
Mar 3, 2022
Dec 20, 2024
Feb 29, 2024
Sep 17, 2022
Jul 7, 2021
Nov 4, 2022
Apr 1, 2024
Jul 27, 2022
Oct 25, 2023
Jan 15, 2025
Mar 21, 2024
Nov 5, 2023
Dec 23, 2021
Jul 25, 2022
Jun 29, 2022
Dec 31, 2023
Sep 2, 2024
Jan 5, 2025
Jul 8, 2022
Jul 26, 2024
Nov 27, 2023
Mar 11, 2023
Nov 7, 2022
Sep 21, 2022
Apr 14, 2023
Oct 16, 2022
Jan 1, 2025
Nov 5, 2022
Dec 19, 2022
Mar 2, 2025
Mar 18, 2024
Jan 25, 2025
Mar 11, 2023
Mar 2, 2025
Oct 3, 2023
May 31, 2023
Dec 28, 2023
May 25, 2024
Jan 8, 2024
Jan 8, 2025
Jan 8, 2024
Jan 11, 2024
Jul 31, 2024
Apr 1, 2024
Apr 1, 2024
Nov 23, 2024
Nov 30, 2024
Dec 27, 2024
Jun 7, 2020
Jan 7, 2024
Mar 7, 2025
Jan 4, 2024
Feb 15, 2025
Jan 5, 2025
May 9, 2024
Jan 4, 2024

Repository files navigation

Shell Examples and Demos

Conventional Commits pre-commit

Repository

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

Conventional Commits

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

Contents

RELEASE_NOTES.md

1๏ธโƒฃ Prequisites

  • Install shellcheck

  • Install vscode extension for shellcheck

    code --install-extension timonwong.shellcheck

โ”Shell Help

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

โ„น๏ธ Useful commands

# list all aliases
alias

# list all functions (zsh)
print -l ${(ok)functions}

00 - Cheatsheet

Cheatsheets are a great way to quickly get an answer to your question.
Steps README.md

01 - Simple argument parsing

Demonstrates how to build a script with simple argument parsing.
Steps README.md

02 - Functions as jobs

Demonstrates how to initiate a function as a job.
Steps README.md

03 - Pipe filters

Demonstrates how read from stdin stream and process it.
Steps README.md

04 - Trap handlers

Demonstrate trap handlers functionality
Steps README.md

05 - Strings

Demonstrate some examples of string manipulation and variables
Steps README.md

06 - Restricted bash shell

Demonstrate a restricted bash shell
Steps README.md

07 - OS Detection

Demonstrate how to detect the OS type in script to change parameters to commands.
Steps README.md

08 - Paths Testing

Demonstrates ways of manipulating paths
Steps README.md

09 - Debian packaging

Demonstrates building a debian package repository
Steps README.md

10 - Functions

Demonstrates different types of techniques for using functions
Steps README.md

11 - Man pages

Demonstrate how to create a manpage.
Steps README.md

12 - CSV parsing

Demonstrate how to parse and work with CSV files.
Steps README.md

13 - Bats

Demonstrate how to use bats for testing
Steps README.md

14 - CI Env Overrides

Demonstrate a way to produce ENV overrides in a CI pipeline
Steps README.md

15 - Screen Control

Demonstrates how to control the termninal screen output
Steps README.md

16 - Globbing

Demonstrates techniques for globbing and operating on sets of files
Steps README.md

17 - Logger

Demonstrates how to implement a logger for scripts
Steps README.md

18 - Bats Mocking

Demonstrates how to test using mocks with bats.
Steps README.md

19 - Timing Operations

Demonstrate how to time operations in the shell to help with optimisation.
Steps README.md

20 - GPG examples

Demonstrate how to use GPG to encrypt and decrpyt files.
Steps README.md

21 - Webserver

Demonstrate how to set up a webserver in bash
Steps README.md

22 - SystemD Service

Demonstrate how to create a systemd service.
Steps README.md

23 - Whiptail Selector

Demonstrate how to use whiptail for file selection.
Steps README.md

24 - Finding files

A few examples on using shell to find files
Steps README.md

25 - Autocompletions

Demonstrate how to write autocomplete scripts
Steps README.md

26 - Cron

Demonstrate how to setup a cronjob
Steps README.md

27 - JournalCtl

Demonstrate how to use journalctl to discover logs
Steps README.md

28 - Old Skool Ascii Banner

An old skool banner printer.
Steps README.md

29 - Imagemagick

Examples of using imagemagick to process images.
Steps README.md

30 - User input

Demonstrate how to use user input in scripts
Steps README.md

31 - Dependency checking

Demonstrates how to check dependencies exist before a script runs
Steps README.md

32 - JQ

Demonstrates some examples of using jq to process json files
Steps README.md

33 - AWSCLI

Demonstrates using awscli to query resources in an AWS account.
Steps README.md

35 - APT and DPKG

Demonstrate examples of working with APT and DPKG
Steps README.md

36 - Git Querying and Examples

Demonstrates some examples of using git queries and tools
Steps README.md

37 - Guid generation

Demonstrates techniques for generating unique ids in scripts.
Steps README.md

38 - Mapping inputs to outputs

Demonstrate how to map an input to an output Steps README.md

42 - yq and yaml

Demonstrates some examples of using yq to process yaml files
Steps README.md

43 - AWK

Demonstrates techniques for using awk to process files.
Steps README.md

44 - Looping over indexed envvars

Demonstrates techniques processing environment variables.
Steps README.md

46 - stdin, stdout and stderr redirection

Demonstrate and work through some stdout and stderr redirection
Steps README.md

47 - FFMPEG

Demonstrate how to use ffmpeg to perform different types of encodings.
Steps README.md

48 - SED

Demonstrates techniques for using sed to process files.
Steps README.md

49 - brew

Demonstrate how to create a brew package.
Steps README.md

50 - tmux and screen

Demonstrate some terminal multiplexors like tmux and screen
Steps README.md

51 - grep and regex

Demonstrates examples of how to use grep and regex.
Steps README.md

52 - xml

Demonstrate how to handle Xml in shell scripts.
Steps README.md

53 - syncing files

Demonstrate some examples syncing directories
Steps README.md

54 - date handling

Demonstrate date handling in shell.
Steps README.md

55 - vim setup

Demonstrates configuring a container for vim
Steps README.md

56 - options handling

Demonstrate how to use shell options in shell scripts.
Steps README.md

58 - gstreamer

Demonstrate some basic gstreamer examples
Steps README.md

59 - monitoring folders

Demonstrate how to monitor a folder for changes using inotify or watchman.
Steps README.md

60 - creating HLS streams from segments

Demonstrates building a hls from individual segments of wav files.
Steps README.md

61 - curl

Demonstrate some common examples with curl
Steps README.md

62 - binary files

Working with binary files in shell.
Steps README.md

63 - md5

Demonstrate how to id files using md5 and md5sum
Steps README.md

64 - calculations

Demonstrate some way of performing calculations in shell and scripts.
Steps README.md

65 - pipes

Demonstrate how to work with anonymous and named pipes.
Steps README.md

66 - generating and renaming files

Demonstrate techniques for generating and renaming files.
Steps README.md

68 - difftools

Example textual diffing tools.
Steps README.md

69 - dotsourcing

Demonstrate how to use dot-sourcing.
Steps README.md

70 - xargs

Demonstrate basic behaviour with xargs.
Steps README.md

71 - disk usage

Demonstrate some examples of calculating disk usage.
Steps README.md

72 - line endings

Demonstrate some examples of working with line-endings differences.
Steps README.md

73 - creating archives

Demonstrate how to create archive files.
Steps README.md

74 - envelope encryption

Demonstrate how to perform envelope encryption.
Steps README.md

75 - just

Demonstrate how just can be used like package.json scripts.
Steps README.md

76 - links

Demonstrate symbolic and hard links.
Steps README.md

78 - dns

Examples for working with DNS.
Steps README.md

79 - hurl

Use hurl to test an API.
Steps README.md

80 - parallel

Demonstrate how to use parallel
Steps README.md

81 - gpu

Demonstrate how to interrogate and use GPU on OS platforms.
Steps README.md

82 - clipboard

Examples of using clipboard in the shell
Steps README.md

๐Ÿ‘€ Resources

  • Google script standards here
  • Understanding tabs output here

Shellchecking

find . -iname '*.sh' -exec shellcheck {} \; 

Pre-commit hook (shellcheck)

Install the pre-commit hook.

# hardlink the script 
ln ./hooks/pre-commit .git/hooks/pre-commit  

Updating RELEASE_NOTES

TURN

docker run -it --rm -v $(pwd):/repo chrisguest/turn --action=create --type=release --includenext --tags