title: Why cat command not working in script
body: <p>I have the following script and it has an error. I am trying to merge all the files into one large file. From the command line the cat commant works fine and the content is printed to the redirected file. From script it is working sometime but not the other time. I dont know why its behaving abnormally. Please help.</p>
  
  <pre><code>#!/bin/bash
  
  ### For loop starts ###
  
  for D in `find . -type d`
  do
  
          combo=`find $D -maxdepth 1 -type f -name "combo.txt"`
          cat $combo &gt;&gt; bigcombo.tsv
  
  done
  </code></pre>
  
  <p>Here is the output of <code>bash -x app.sh</code></p>
  
  <pre><code>++ find . -type d
  + for D in '`find . -type d`'
  ++ find . -maxdepth 1 -type f -name combo.txt
  + combo=
  + cat
  ^C
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  The following worked for me. There was issue with the path. I still dont know what was the issue so answer is welcome.</p>
  
  <pre><code>#!/bin/bash
  
  ### For loop starts ###
  rm -rf bigcombo.tsv
  
  for D in `find . -type d`
  do
  
                  psi=`find $D -maxdepth 1 -type f -name "*.psi_filtered"`
                  # This will give us only the directory path from find result i.e. removing filename.
                  directory=$(dirname "${psi}")
                  cat $directory"/selectedcombo.txt" &gt;&gt; bigcombo.tsv
  
  
  done
  </code></pre>