title: What is the best way to accept a 2nd user input from options defined by the 1st user input?
body: <p>My background is in SQL but I've been learning Bash to create tools to help non-Linux users find what they need from my Linux system - I am pretty green with Bash, I apologize if this looks a bit dumb.</p>
  <p>The goal of the script is to essentially display all directories within the current directory to the user, and allow them to input 1-9 to navigate to lower directories.</p>
  <p>My sticking point is that I'm trying to use arrays to define potential filepaths, since in practice new directories will be added over time and it is not practical to edit the script each time a filepath is added.</p>
  <p>Here's my prototype so far, currently it navigates into Test1, Test2, or Test3 then echos pwd to prove it is there.</p>
  <pre><code>#Global Variables
  DIR_MAIN='/home/admin/Testhome'
  
  #Potential Filepaths
  #/home/admin/Testhome/Test1/Test1-1/
  #/home/admin/Testhome/Test1/Test1-2/
  #/home/admin/Testhome/Test2/Test2-1/
  #/home/admin/Testhome/Test2/Test2-2/
  #/home/admin/Testhome/Test3/Test3-1/
  #/home/admin/Testhome/Test3/Test3-2/
  
  #Defining Array for first user input
  arr=($(ls $DIR_MAIN))
  
  #System to count total number of directories in filepath, then present to user for numbered selection
  
  cnt=0
  for i in ${arr[@]}
  do
      cnt=$(($cnt+1))
      echo &quot;$cnt) $i&quot;
  done
  
  read -p &quot;Select a folder from the list: &quot; answer
  case $answer in
      1)
      cd $DIR_MAIN/${arr[0]}
          echo &quot;Welcome to $(pwd)&quot;
      ;;
      2)
          cd $DIR_MAIN/${arr[1]}
          echo &quot;Welcome to $(pwd)&quot;
      ;;
      3)
      cd $DIR_MAIN/${arr[2]}
          echo &quot;Welcome to $(pwd)&quot;
      ;;
  esac
  </code></pre>
  <p>I've tried the following, but it doesn't like the syntax (to someone experienced I'm sure these case statements look like a grenade went off in vim).</p>
  <p>I'm beginning to wonder if the SELECT CASE road I'm going down is appropriate, or if there is an entirely better way.</p>
  <pre><code>#User Input Start
  echo &quot;What is the secret number?&quot;
  while :
  do
      read STRING1
      case $STRING1 in
      1)
          echo &quot;Enter the number matching the directory you want and I will go there&quot;
          echo &quot;1 - ${arr[0]}&quot;
          echo &quot;2 - ${arr[1]}&quot;
          echo &quot;3 - ${arr[2]}&quot;
              read STRING2
              case $STRING2 in
                  1) 
                  cd $DIR_MAIN/${arr[0]}
                  echo &quot;Welcome to&quot; $(pwd)
                  2) 
                  cd $DIR_MAIN/${arr[1]}
                  echo &quot;Welcome to&quot; $(pwd)
                  3)
                  cd $DIR_MAIN/${arr[2]}
                  echo &quot;Welcome to&quot; $(pwd)
                  *)
                  echo &quot;Thats not an option and you know it&quot;
      *)
          echo &quot;1 is the secret number, enter 1 or nothing will happen&quot;
          ;;
      esac
      #break needs to be down here somewhere
  done
  </code></pre>
  <p>Ultimately I know I'll need to variabilize a local array once I'm in Test2 for example (since in practice, this could descend as far as /Test2/Test2-9 and there would be tons of redundant code to account for this manually).</p>
  <p>For now, I'm just looking for the best way to present the /Test2-1 and /Test2-2 filepaths to the user and allow them to make that selection after navigating to /Test2/</p>