| 1 | # Two functions I actually use, all the time.
 | 
| 2 | #
 | 
| 3 | # To keep depenedencies small, this library will NEVER grow other functions
 | 
| 4 | # (and is named to imply that.)
 | 
| 5 | #
 | 
| 6 | # Usage:
 | 
| 7 | #   source --builtin two.sh
 | 
| 8 | #
 | 
| 9 | # Examples:
 | 
| 10 | #    log 'hi'
 | 
| 11 | #    die 'expected a number'
 | 
| 12 | 
 | 
| 13 | if command -v module >/dev/null; then  # include guard for YSH
 | 
| 14 |   module two || return 0
 | 
| 15 | fi
 | 
| 16 | 
 | 
| 17 | log() {
 | 
| 18 |   ### Write a message to stderr.
 | 
| 19 |   echo "$@" >&2
 | 
| 20 | }
 | 
| 21 | 
 | 
| 22 | die() {
 | 
| 23 |   ### Write an error message with the script name, and exit with status 1.
 | 
| 24 |   log "$0: fatal: $@"
 | 
| 25 |   exit 1
 | 
| 26 | }
 | 
| 27 | 
 |