title: How to implement tree command in bash/shell script?
body: <p>I tried to implement in bash some code which output would be similar to the "tree" command in the terminal.</p>
  
  <p>Here it is:</p>
  
  <pre><code>listContent() {
      local file
      for file in "$1"/*; do
          if [ -d $file ]; then
              countSpaces $file
              echo $?"Directory: $file"
              listContent "$file"
          elif [ -f $file ]; then
              countSpaces $file
              echo $?"File: $file"
          fi
      done
  }
  
  countSpaces() {
      local space="   "
      for (( i=0; i&lt;${#$1}; i++ )); do
          if [ ${file:$i:1} = "/" ]; then
          space = space + space
          return space
      done
  }
  
  listContent "$1"
  </code></pre>
  
  <p>Running the script I give: ./scriptName.sh  directoryName
  where scriptName is my script and directoryName is the argument which is the name of the directory from which the code should start.</p>
  
  <p>I would like to see the output like this:</p>
  
  <pre><code>Directory: Bash/Test1Dir
      File: Bash/Test1Dir/Test1Doc.txt
  Directory: Bash/Test2Dir
      Directory: Bash/Test2Dir/InsideTest2DirDir
          File: Bash/Test2Dir/insideTest2DirDoc.txt
  File: Bash/test.sh
  </code></pre>
  
  <p>But I have some troubles in completing this code. Could someone help me figure it out why it isn't working and what should I change?</p>
  
  <p>Will be grateful.</p>