title: Bash Script to validate the existence of User Name in /etc/passwd
body: <p>I want to create a Bash Script to check the existence of a user name in <code>/etc/passwd</code>. If it exists then add it to <code>users.txt</code> file.</p>
  
  <p>I am not really good at UNIX programming, so I hope somebody can help me.</p>
  
  <pre><code>while(get to the end of /etc/passwd){
  
    name=$(cat /etc/passwd | cut -d: -f1);
    num1=$(cat /etc/passwd | cut -d: -f3);
    num2=$(cat /etc/passwd | cut -d: -f4);
  
    if(num1==num2)
     /*i compare argv[0] with $name */
     /* if true i=1 */
  
  }
  
  if(i==1)
    save following string "argv[0]=agrv[1]"
  else
    "error message"
  </code></pre>