The post is screaming school assignment, but it was so easy that I found it difficult to provide examples of what you will need to check for while trying not to write the script for you. Here is my poor attempt:
Code:
#!/bin/sh
PASSWORD_FILE="/etc/passwd"
if [ $# -eq 1 ]; then
USER_NAME="$1"
REGX_USER_NAME="^$USER_NAME:"
PASS_ENTRY=`cat $PASSWORD_FILE | grep $REGX_USER_NAME`
if [ $? -eq 0 ]; then
# ...
USER_ID=`echo $PASS_ENTRY | cut -d':' -f3`
# ...
else
echo "Username: $USER_NAME not found"
fi
else
echo "Usage: ScriptName username"
fi
exit
[*]$# is the number of parameters passed into the script[*]$1 is the first parameter[*]The regular expression was needed to make sure that grep only found the username at the begining of the line.[*]$? is the result from the last command run (grep). If it's zero then grep did find a match.[*]Read the man page for cut, it's simple.[*]Remember that you can use bash -x scriptname to debug the script.