脚本练习_输入用户名 检测用户是否存在 存在则检测家目录是否存在

#!/bin/bash

## Script Filename : check_home.sh.
## Writen by Wangxiaoqiang 2014/12/17.

read -p "Please input a username : " username

[ "${username}" == "root" ] && echo " ${username}'s homedir is exist,very good ! " \
                            && exit 0

grep "^\b${username}\b" /etc/passwd > /dev/null

if [ $? -eq 0 ];then
  [ -e "/home/${username}" ] && echo " ${username}'s homedir is exist,very good ! " \
                             || echo " ${username}'s homedir isn't exist,so bad ! "
else
  echo " ${username} user not exist , bye . "
fi

# End




你可能感兴趣的:(Scripts)