title: Reference a file name in shell script inside of a "for each" block
body: <p>I have a task that I would like to add more automation into. Basically, I will have a directory that has a varying amount of files that start with the letter x. I want to run a script on each of these files, and then move the file into a "completed" folder.</p>
  
  <p>I only want to loop through files that have an "x" as the starting character of the filename, and then use that filename in another spot as a part of an output filename.</p>
  
  <p>Something along the lines of:</p>
  
  <pre><code>for each (files beginning with x)
    cat (filename) | xargs ./script.sh &gt; result-(filename);
    mv (filename) complete/;
    mv result-(filename) complete/;
  end for each
  </code></pre>
  
  <p>I've been manually expanding out a shell script each time this comes up, and sizing it to exactly how many files I have, but I am sure what I am asking is possible.</p>