title: Pass CAT command as argument to function
body: <p>I'm trying to write a very simple bash script that modifies a number of files, and I'm outputting the results of each command to a log as a check whether the command was completed successfully. Everything appears to be working except I can't pass CAT with variables to my script -- I keep getting a <code>cat: &gt;&gt;: No such file or directory</code> error.</p>
  
  <pre><code>#! /bin/bash
  
  file1="./file1"
  file2="./file2"
  
  check () {
    if ( $1 &gt; /dev/null ) then
      echo "     $1 : completed" | tee -a log
      return 0;
    else
      echo "ERR&gt; $1 : command failed" | tee -a log
      return 1;
    fi
  }
  
  check "cp $file1 $file1.bak"            # this works fine
  check "sed -i s/text/newtext/g $file1" # this works, too
  check "cat $file1 &gt;&gt; $file2"          # this does not work
  </code></pre>
  
  <p>I've tried any number of combinations of quoting the command. The only way that I can get it to work is by using the following:</p>
  
  <pre><code>check $(cat $file1 &gt;&gt; $file2)
  </code></pre>
  
  <p>However, this does not pass the command itself to <code>check</code> only the return value, so <code>$1</code> in function <code>check</code> carries <code>/dev/null</code> and not the command performed, which is not the particular behaviour I want.</p>
  
  <p>Just for completeness, the <code>log</code> file looks like:</p>
  
  <pre><code>     cp ./file1 ./file1.bak : completed
       sed -i s/text/newtext/g ./file1 : completed
  ERR&gt; cat ./file1 &gt;&gt; ./file2 : command failed
  </code></pre>
  
  <p>I'm sure the solution is rather simple, but it has eluded me for a few hours and no amount of Google searches has yielded any help. Thanks for having a look.</p>