Skip to content

DevelopersToolbox/bash-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevelopersToolbox logo
Github Build Status License Created
Release Released Commits since release

Overview

This is a collection of useful(ish) bash snippets. The snippets are all simple self-contained pieces of code (a class or subroutine), but non of them are large enough to require having a repository in their own right.

Bash Snippets

Name Description
abs.sh The Math. abs() function returns the absolute value of a number. That is, it returns x if x is positive or zero, and the negation of x if x is negative.
array-contains.sh Check to see if an array contains a specific value.
array-to-string.sh Convert an array to a string with a custom separator and a final optional value.
center-text.sh Center any given text on the screen (optional define the screen width).
check-prerequisites.sh Check prerequisite commands are installed.
compare-versions.sh Compare two version strings with optional custom delimiter.
contains.sh Check to see if one string contains another.
countdown.sh Display a simple countdown timer and message.
error-messages.sh Display error, warning and success messages.
get-confirmation.sh Get user confirmation for an action.
get-git-root.sh Get the root directory of a given git repo (and handle correctly when it isn't a git repo).
get-script-info.sh Get information about a script (full path and script name).
get-terraform-version.sh Get the current terraform version.
get-version-string.sh Extract a semver version from a string.
is-git-repo.sh Check if a given directory contains a git repo.
rollingback.sh Using signals to create rollback functions for cleaner scripting.
stacktrace.sh Provide a stack trace for from main to the point of of calling the stacktrace.
strict-mode.sh An example of a 'strict' mode setup for bash scripts.
sudo-librarian-puppet.sh Run librarian-puppet via sudo without changing default sudoers file (Debian 9 / Puppet 5).
terminal-or-not.sh A script to allow to determine if your script is attached to a terminal, pipe or redirection.
untag.sh A simple script to remove ALL tags from a git repo.
using-colour.sh An example of how to use colour (see bash-colour-include for a full working solution).
using-set.sh Using 'set' for more robust shell scripting.
variable-replace.sh Replace template variables in a file with values from an associative array.
verbose-mode.sh Demonstration of script wide verbose/silent mode.