Created
January 12, 2019 16:14
-
-
Save sam016/bcceca6498ea1b53e3fcdb791c608073 to your computer and use it in GitHub Desktop.
Awsome Bash Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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