title: Awk-Command Line to Script Arguments as Variable to Search For Specific Field
body: <p>So I'm trying to write a script that will take an argument from the command line and use said variable as the field parameter to print. The script must use any number or NF.</p>
  
  <p>So,</p>
  
  <pre><code>echo a b c | ./awkprint.sh 1 
  </code></pre>
  
  <p>would print the first field (a) </p>
  
  <p>and, </p>
  
  <pre><code>echo a b c | ./awkprint.sh NF 
  </code></pre>
  
  <p>would print the last field (c).</p>
  
  <p>Here's what I have for the line in the script</p>
  
  <pre><code>awk -v awkvar=$1 '{print $awkvar}'
  </code></pre>
  
  <p>It works perfectly for any number that I use on the command line...however as soon as I use NF it seems to treat it as $0 and print all fields so I get:</p>
  
  <pre><code>echo a b c | ./awkprint.sh NF
  
  a b c
  </code></pre>
  
  <p>instead of,</p>
  
  <pre><code>echo a b c | ./awkprint.sh NF
  
  c
  </code></pre>
  
  <p>What am I doing wrong?</p>