Add __os magic var

This commit is contained in:
Kevin van Zonneveld 2016-02-16 22:19:08 +01:00
parent cbe70aa80e
commit 915f858d5e
3 changed files with 14 additions and 8 deletions

View File

@ -64,6 +64,7 @@ For more information on SemVer, please visit [http://semver.org](http://semver.o
- Enable errexit, nounset and pipefail at the top
- More refined colors (thanks @arathai)
- Add Changelog
- Add `__os` magic var
- Add `__base` magic var
- Enable long, GNU style options (thanks @zbeekman)

16
main.sh
View File

@ -59,8 +59,10 @@ EOF
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__os="Linux"
if [[ "${OSTYPE:-}" == "darwin"* ]]; then
__os="OSX"
fi
### Functions
#####################################################################
@ -221,17 +223,17 @@ fi
### Runtime
#####################################################################
if [[ "${OSTYPE:-}" == "darwin"* ]]; then
info "You are on OSX"
else
info "You are on Linux"
fi
info "__file: ${__file}"
info "__dir: ${__dir}"
info "__base: ${__base}"
info "__os: ${__os}"
info "arg_f: ${arg_f}"
info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}"
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
debug "Info useful to developers for debugging the application, not useful during operations."
info "Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required."
notice "Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required."

View File

@ -1,6 +1,9 @@
B3BP:STDIO_REPLACE_DATETIMES
{datetime} UTC [ debug] cli arg arg_f = () -> {tmpdir}/x
{datetime} UTC [ info] You are on {os}
{datetime} UTC [ info] __file: {root}/main.sh
{datetime} UTC [ info] __dir: {root}
{datetime} UTC [ info] __base: main
{datetime} UTC [ info] __os: {os}
{datetime} UTC [ info] arg_f: {tmpdir}/x
{datetime} UTC [ info] arg_d: 0
{datetime} UTC [ info] arg_v: 0