title: How to make an executable shell script to run my .py program and input a file
body: <p>I have a python program that takes a file as input from std input, runs some calculations on the data, and outputs results to std output. Here is the code I am using for getting the input file:</p>
  
  <pre><code>import math
  import sys
  
  name = sys.argv[-1]
  inf = open(name, 'r') 
  outf = open("test.txt", 'w')
  
  col1, col2, col3 = [], [], []
  for row in inf:
      a, b, c = row.split('\t')
      col1.append(a)
      col2.append(b)
      col3.append(c)
  </code></pre>
  
  <p>I need to create a shell script to execute the program and provide the input file. Ideally the shell script should work so that it can be used as follows:</p>
  
  <pre><code>$ cat inputfile.txt | scriptname
  </code></pre>
  
  <p>and/or</p>
  
  <pre><code>$ ./scriptname &lt; inputfile
  </code></pre>
  
  <p>I have tried a couple of different basic shell scripts but haven't had any luck in getting this to work. I would appreciate any suggestions on how to make this script and/or how to modify my python code to make this work. Thanks!</p>
  
  <p>If it helps, I beleive I am using python 2.7.3 on mac osx 10.8</p>
  
  <p>P.S. This is actually my first experience programming (i started learning python just for this project) so please excuse the crappy code.</p>