title: bash script: printLine() function not being called in main
body: <p>My overall goal is to output an 8x8 checkerboard pattern to the terminal screen. I have a recursive function I've written, to print one 8x1 row of the checkerboard starting with a black or white tile depending on whether I call the script from the terminal with an option flag or not. This function is called printLine() and I believe it works perfectly. However, when I call it in my loops in main(), it is only executed once, and then the program continues to run as if waiting for user input. </p>
  
  <p>Like I said, I'm pretty confident in printLine(), and I'm also confident that the loops in main() works, as I've replaced the printLine() function call with a simple echo "hi" statement, and it prints "hi"as many times as the loop specifies when I run the script, so I'm not sure why the loops don't call printLine() iteratively when their bodies consist of it rather than the simple echo statement. There's some unused constants I haven't used yet just for testing purposes, so please ignore those. </p>
  
  <pre><code># Script 1 - Checkerboard 
  # 
  # Name: xxx  
  # PID: xxx  
  # Account: xxx  
  
  # ============================== DO NOT CHANGE ============================== #
  
  # Constants used
  TILE_BLACK="\033[0;40m  \033[0;0m"    # DO NOT CHANGE
  TILE_WHITE="\033[0;47m  \033[0;0m"    # DO NOT CHANGE
  SQUARES_PER_LINE=8                    # DO NOT CHANGE
  HALF_DIVISOR=2                        # DO NOT CHANGE
  NUM_ITERATIONS=4                      # DO NOT CHANGE
  ERR="\tERROR: Invalid flag given.\n"  # DO NOT CHANGE
  USAGE="USAGE: ./checkerboard.sh [-r]" # DO NOT CHANGE
  
  rotate_flag="f"
  
  # Parse command line arguments
  while getopts ":r" arg $@; do
    case $arg in
  
      # rotation wanted
      r) rotate_flag="t";;
  
      # Invalid flag provided
     \?) echo; echo -e "$ERR"; echo "$USAGE"; exit 1;;
  
    esac
  done
  
  # Remove parsed option flags
  shift $((OPTIND - 1))
  
  # ========================= YOUR CODE STARTS BELOW ========================= #
  
  # FIXME: Write a function that prints one row of the checkerboard. It should
  # look at the argument passed in to determine if it will start by printing a
  # white or black square. This is an optional method, but will help you
  # implement the main method.
  count=0;
  function printLine() { # One way to define a function
      until [ "$count" == 8 ]; do
      if  [ "$1" ==  "$TILE_WHITE" ]; then
      echo -en "$TILE_WHITE "
      count=$(($count + 1))
      printLine "$TILE_BLACK"
    elif [ "$1" == "$TILE_BLACK" ]; then       
      echo -en "$TILE_BLACK"
      count=$(($count + 1))
      printLine "$TILE_WHITE"
    fi
    done
  }
  
  function main() { # Another way to define a function
  
    counter=0
  
    if [ $rotate_flag == "t" ]; then
      # This line creates a loop that will run NUM_ITERATIONS times
      #while (!cond)
      until [ "$counter" == 4 ]; do
  
        # FIXME: Use the print functions to draw two REVERSED rows of the board
        count2=0;
        until [ "$count2" == 2 ]; do
           printLine "$TILE_BLACK"
           printLine "$TILE_WHITE"
           count2=$(($count2 + 1))
        done
        counter=$(($counter + 1))
     done
  
    else
      until [ $counter -eq $NUM_ITERATIONS ]; do
        # FIXME: Use the print functions to draw two rows of the board
        count3=0;
        until [ "$count2" == 2 ]; do
           printLine "$TILE_BLACK"
           printLine "$TILE_WHITE"
           count3=$(($count3 + 1))
        done
        counter=$(($counter + 1))
      done
    fi
  }
  
  # ============================== DO NOT CHANGE ============================== #
  main # Calls the main function to start the script up
  exit 0      
  </code></pre>