title: How do I loop through a directory path stored in a variable
body: <p>I'm teaching my self bash and trying to create a script that will loop through the directories contained within a given directory (or the current directory, if none is supplied).</p>
  
  <p>This is the script I have so far:</p>
  
  <pre><code>#!/bin/bash
  start_dir=${1:-`pwd`}       # set to current directory or user supplied directory
  echo start_dir=$start_dir
  
  for d in $start_dir ; do
      echo dir=$d
  done
  </code></pre>
  
  <p>First, all this script currently does is sets <code>d</code> to  <code>start_dir</code> abd echos the value in <code>start_dir</code>.  I guess this makes sense, but I was hoping it would actually loop through the directory.  How do I get this to actually loop through the directory set in the <code>start_dir</code> variable?</p>
  
  <p>Also, I'm wanting to only loop through the directories.  <a href="https://unix.stackexchange.com/a/86724/90462">This answer</a>, shows that putting a <code>/</code> after the path will ensure only directories are returned to the for loop.  Is there a way to incorporate this to ensure looping over <code>start_dir</code> will only return directories, given that there is a possibility that the user will not provide a directory path to the script?</p>
  
  <p>Cheers</p>