Shell Script to print login information
Program
#Zero arguments error
if [ $# -eq 0 ]
then
echo "Can't have zero arguments!"
else
for login in $*
do
if grep $login /etc/passwd >/dev/null
then
echo "Login name: $login"
dir=`grep $login /etc/passwd | cut -d ":" -f 6`
echo "Home Directory: $dir"
else
echo "$login is not a valid login id!"
fi
done
fi
Output 1
$ sh login-info.sh
Can't have zero arguments!
Output 2
$ sh login-info.sh root
Login name: root
Home Directory: /root
Output 3
$ sh login-info.sh user
Login name: user
Home Directory: /
/
/
/run/saslauthd
/
/var/lib/nfs
/
/dev/null
Output 4
$ sh login-info.sh undef
undef is not a valid login id!