#!/usr/bin/env bash

set -o nounset -o noglob +o braceexpand
shopt -s lastpipe

recursive_function () {
  local start="${1}"
  local depth="$(( ${2} + 1 ))"
  printf '%s\n' "beginning at depth ${depth}"
  local number
  my_seq "${start}" 100 |
    while IFS='' read -r number; do
      if (( number % 50 == 0 )); then
        recursive_function "$(( start + 75 ))" "${depth}"
      fi
      local line
      printf 'read me\n' |
        IFS='' read -r line
      #
    done
  #
  local -a save_PIPESTATUS=( "${PIPESTATUS[@]}" )
  declare -p save_PIPESTATUS
  if (( save_PIPESTATUS[0] != 0 )); then
    printf '%s\n' "Bad. Ow."
  fi
  printf '%s\n' "ending at depth ${depth}. start was ${start}."
}

my_seq () {
  local -i start="${1}"
  local -i end="${2}"
  seq "${@}"
  (( start < end ))
}

recursive_function 0 0
