#!/usr/bin/env bash # # v1: initial version # v2: cleanup, replaced while loops with for loops when possible # external tools: none # set to 0 to disable log function output, 1 otherwise debug=0 declare -a abilities=( strength dexterity intelligence wisdom charisma constitution ) usage() { echo "dnd_characters.sh generate|modifier " >&2 exit 1 } # log function takes 1 argument which is echoed if $debug is > 0 # todo: Add another argument (mask ?) to selectively log portions of code log () { (( $debug )) && echo "$*" } # simple bubble sort for numeric array (descending) # args: 1: the array # todo: add a parameter for asc/desc order. sort_n() { local -a array=( "$@" ) local -i max=$(( ${#array[@]} - 1 )) for (( max= $(( ${#array[@]} - 1 )); max > 0; max-- )); do local -i i for (( i=0; i