Q: Retrieving infor for certain users in linux I have this code to generate user account info. the problem is I have a line for user name where you will type a user name and only retrieve the information for that specified user name. but the code retrieves information for all users on the system.
#! /bin/bash
#This script returns import information about the  user name on the system

echo "PLease enter  name to continue:"

read SuppliedName
for user in $(cut -d: -f1 /etc/passwd)
#while [ "$SuppliedName" == "$USER" ]
do
IFS=$'\n'

userinfo=$(grep $user: /etc/passwd)

comment=$(echo $userinfo | cut -d: -f5)
home=$(echo $userinfo | cut -d: -f6)
groups=$(groups $user | cut -d: -f2)

#Skip users that do not have '/home' in the path to their home directory
if [ $(echo "$home" | grep -v '/home/') ]
then
    continue
fi

echo "Username: $user"
echo "User Info: $comment"
echo "Home Directory: $home"
echo "Groups: $groups"

echo "Disk usage: $(du -sh $home)"

last=$(last $user | head -1)
if [ $( echo $last | wc -c ) -gt 1 ]
then
    echo "Last login: "
    echo "$last"
else
    echo "User has never logged in!"
fi
echo ""
echo "--"
echo ""
done


A: *

*You're missing comparison between $user and $suppliedName, and since you are iterating over /etc/passwd to get all user data, you print it.

*grep $user: /etc/passwd will grep all lines which contains  '$user:' including those users who has GECOS starting with that name (correct regex is ^$user:)

*This code only checks local users, so no LDAP. The cleaner way is to use getent.

All in all, i would be using finger for this. Or rewritten main loop as:
getent passwd $suppliedName | ( 
    IFS=: 
    while read UNAME SHADOW UID_ GID GECOS HOME SHELL ; do 
        # Your code goes here
    done )


A: You can do this another way with a lot less effort and handle the non-match a bit more gracefully, e.g.
#!/bin/bash

printf "PLease enter name to continue: "    ## use printf

read -r name

info="$(grep "^$name" /etc/passwd)"         ## read line into info

if [ -n "$info" ]; then     ## test that info is not empty, then call awk
    awk -F : '{printf "Username: %s\nUser Info: %s\nHome Directory: %s\n", $1, $5, $6 }' \
    <<< "$info"             ## use herestring to feed data to awk
    printf "Groups: %s\n" "$(groups "$name")"       ## use groups
else
    printf "error: name not found '%s'\n" "$name"   ## handle error/no match
fi

Example Use/Output
$ bash getuser.sh
PLease enter name to continue: david
Username: david
User Info: David C. Rankin
Home Directory: /home/david
Groups: david : david adm lp sys uucp wheel vboxusers

