Commit 036a0ec7 authored by John A's avatar John A

Simplify version check and string parsing

parent bcbda041
......@@ -41,9 +41,8 @@ verbose=0
seed="$RANDOM"
# ensure Bash version >= 4.0
ver="$(printf '%s' "$BASH_VERSION" | cut -d . -f 1)"
if [ -z "$ver" ] || [ "$ver" -lt 4 ]; then
printf '%s\n' "Error: requires Bash v4.0 or higher. You have version $BASH_VERSION."
if ((BASH_VERSINFO[0] < 4)); then
printf '%s\n' "Error: bonsai.sh requires Bash v4.0 or higher. You have version $BASH_VERSION."
fi
# ensure MacOS compatibility with GNU getopt
......@@ -281,7 +280,7 @@ done
declare -A leafArray
leafArrayLen=0
# parse each string in comma-separated $leafStrs
for str in $(printf '%s' "$leafStrs" | tr , '\n'); do
for str in ${leafStrs//,/$'\n'}; do
leafArray[$leafArrayLen,0]=${#str} # first item in sub-array is length
......@@ -549,7 +548,7 @@ branch() {
[ $dy -gt 0 ] && chars=('\\') # growing down
[ $dy -eq 0 ] && chars=('_' '/') # not growing
;;
esac
esac
# randomly choose leaf character
if [ $life -lt 4 ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment