Skip to content

Instantly share code, notes, and snippets.

@sam016
Created January 12, 2019 16:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam016/bcceca6498ea1b53e3fcdb791c608073 to your computer and use it in GitHub Desktop.
Save sam016/bcceca6498ea1b53e3fcdb791c608073 to your computer and use it in GitHub Desktop.
Awsome Bash Snippets
#!/bin/bash
# author:
# https://stackoverflow.com/a/28709668/1957036
cecho() {
local code="\033["
case "$1" in
black | bk) color="${code}0;30m";;
red | r) color="${code}1;31m";;
green | g) color="${code}1;32m";;
yellow | y) color="${code}1;33m";;
blue | b) color="${code}1;34m";;
purple | p) color="${code}1;35m";;
cyan | c) color="${code}1;36m";;
gray | gr) color="${code}0;37m";;
*) local text="$1"
esac
[ -z "$text" ] && local text="$color$2${code}0m"
echo "$text"
}
cecho "Normal"
cecho y "Yellow!"
#!/bin/sh -
# author
# https://superuser.com/a/186279
# idiomatic parameter and option handling in sh
while test $# -gt 0
do
case "$1" in
--opt1) echo "option 1"
;;
--opt2) echo "option 2"
;;
--*) echo "bad option $1"
;;
*) echo "argument $1"
;;
esac
shift
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment