title: How can I tokenize $PATH by using awk?
body: <p>How can I tokenize $PATH by using awk?</p>
  
  <p>I tried 3 hours, but it totally screwed out.</p>
  
  <pre><code>#!/bin/bash
  
  i=1
  
  while true; do
    token=$($echo $PATH | awk -F ':' '{print $"$i"}')
  
    if [ -z "$token" ]; then
      break
    fi  
  
    ((i++))
  
    if [ -a "$TOKEN/$1" ]; then
      echo "$TOKEN/$1"
      break
    fi  
  
    break
  done
  </code></pre>
  
  <p>When I run this code, I got</p>
  
  <pre><code>/home/$USERID/bin/ff: line 6: /home/$USERID/bin:/usr/local/symlinks:/usr/local/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/$USERID/bin: No such file or directory
  </code></pre>
  
  <p>How can I change my program?</p>