title: Calling Awk in a shell script
body: <p>I have this command which executes correctly if run directly on the terminal. </p>
  
  <pre><code>awk '/word/ {print NR}' file.txt | head -n 1
  </code></pre>
  
  <p>The purpose is to find the line number of the line on which the word <code>'word'</code> first appears in <code>file.txt</code>.</p>
  
  <p>But when I put it in a script file, it doens't seem to work.</p>
  
  <pre><code>#! /bin/sh
  
  if [ $# -ne 2 ]
  then
          echo "Usage: $0 &lt;word&gt; &lt;filename&gt;"
          exit 1
  fi
  
  awk '/$1/ {print NR}' $2 | head -n 1
  </code></pre>
  
  <p>So what did I do wrong?</p>
  
  <p>Thanks,</p>