title: Bash - Iterating over select menu options after choosing an option?
body: <p>I am reading up on Select menus in Bash:</p>
  
  <p><a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_06.html" rel="nofollow noreferrer">Making menus with the select built-in</a></p>
  
  <p>I am quite confused when it comes to iterating over the options in the menu and would appreciate any feedback on this.</p>
  
  <p>Using the code here as a starting point:</p>
  
  <p><a href="https://askubuntu.com/a/1716/243213">How can I create a select menu in a shell script?</a></p>
  
  <p>We get the following output:</p>
  
  <pre><code>root@dev:~/# ./test.sh
  1) Option 1
  2) Option 2
  3) Option 3
  4) Quit
  Please enter your choice: 1
  you chose choice 1
  Please enter your choice: 2
  you chose choice 2
  Please enter your choice: 4
  root@dev:~/#
  </code></pre>
  
  <p>What I would like to try to do, is show the select options again once an option has been chosen, so the output would be like:</p>
  
  <pre><code>root@dev:~/# ./example.sh
  1) Option 1
  2) Option 2
  3) Quit
  Please enter your choice: 1
  you chose choice 1
  1) Option 1
  2) Option 2
  3) Quit
  Please enter your choice: 2
  you chose choice 2
  1) Option 1
  2) Option 2
  3) Quit
  Please enter your choice: 3
  root@dev:~/#
  </code></pre>
  
  <p>So I have given this a Bash (L) and and tried to loop through the options (array?):</p>
  
  <pre><code>#!/bin/bash
  
  PS3='Please enter your choice: '
  options=("Option 1" "Quit")
  select opt in "${options[@]}"
  do
    case $opt in
      "Option 1")
        echo "you chose choice 1"
        # Create an incrementing value
        loop=1;
        # Loop through each option
        for option in ${options[@]} ; do
          # Echo the option
          echo "$loop) $option";
          # Increment the loop
          loop=$((loop+1));
        done
        ;;
      "Quit")
        break
        ;;
      *) echo invalid option;;
    esac
  done
  </code></pre>
  
  <p>But then I get an output like:</p>
  
  <pre><code>root@dev:~/# ./stumped.sh
  1) Option 1
  2) Quit
  Please enter your choice: 1
  you chose choice 1
  1) Option
  2) 1
  3) Quit
  Please enter your choice:
  </code></pre>
  
  <p>So it seems that the array values are separated by spaces here?</p>
  
  <p>To my understanding: <code>options=("Option 1" "Quit")</code> is creating an array of 2 values and not of 3 however it is being interpreted in Bash as 3 and I am not sure why.</p>
  
  <p>Could someone enlighten me and explain why this is happening?</p>