new to bash scripting so just wondering if i am doing this code right at all. im trying to search /etc/passwd and then grep and print users.
usage ()
{
echo "usage: ./file.sk user"
}
# test if we have two arguments on the command line
if [ $# != 1 ]
then
usage
exit
fi
if [[ $# < 0 ]];then
usage
exit
fi
# Search for user
fullname=`grep $1 /etc/passwd | cut -f 5 -d :`
firstname=`grep $1 /etc/passwd | cut -f 5 -d : | cut -f 1 -d " "`
#check if there. if name is founf: print msg and line entry
not sure as how to this or if im doing this right...
am i doing this right?
$#
test is redundant, if the code reaches it$#
must be 1. – Kevin Jan 16 '12 at 19:06finger
command. – Kevin Jan 16 '12 at 19:10<
is redirection, not numeric comparison. As others have pointed out, the condition is redundant anyway, but this error could be pretty hard to debug, so I'm pointing it out separately. – tripleee Jan 16 '12 at 19:59