Skip to content

Instantly share code, notes, and snippets.

@nbomberger
Forked from Gen2ly/template
Last active December 17, 2015 00:09
Show Gist options
  • Save nbomberger/5518899 to your computer and use it in GitHub Desktop.
Save nbomberger/5518899 to your computer and use it in GitHub Desktop.
This is a Bash script template with colors. I replaced the '\e' with '\x1B' to make it work with OSX's terminal colors.
#!/bin/bash
# Description of script
# Required program(s)
req_progs=(prog1 prog2)
for p in ${req_progs[@]}; do
hash "$p" 2>&- || \
{ echo >&2 " Required program \"$p\" not installed."; exit 1; }
done
# Display usage if no parameters given
if [[ -z "$@" ]]; then
echo " ${0##*/} <input> - description"
exit
fi
# Text color variables
xtred='\x1B[0;31m' # red
txtgrn='\x1B[0;32m' # green
txtylw='\x1B[0;33m' # yellow
txtblu='\x1B[0;34m' # blue
txtpur='\x1B[0;35m' # purple
txtcyn='\x1B[0;36m' # cyan
txtwht='\x1B[0;37m' # white
bldred='\x1B[1;31m' # red - Bold
bldgrn='\x1B[1;32m' # green
bldylw='\x1B[1;33m' # yellow
bldblu='\x1B[1;34m' # blue
bldpur='\x1B[1;35m' # purple
bldcyn='\x1B[1;36m' # cyan
bldwht='\x1B[1;37m' # white
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtrst='\x1B[0m' # Text reset
# Feedback indicators
info=${bldwht}*${txtrst}
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}
# Indicator usage
echo -e "${info} "
echo -e "${pass} "
echo -e "${warn} "
# Check if root
if [ $(whoami) != root ]; then
echo " Must be root to use."
exit
fi
# Check if selection exists
if [ ! -e "$@" ]; then
echo " Selection \""$@"\" does not exist."
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment