1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/www [root@centos6 ~]#cat usermagedu.sh #!/bin/bash #接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/www id $1 &>/devnull if [ $? -eq 0 ];then echo 用户$1 已存在! else useradd -d $2 $1 && echo "用户$1 已创建,家目录为$2 !" fi [root@centos6 ~]#bash usermagedu.sh root 用户root 已存在! [root@centos6 ~]#bash usermagedu.sh magedu /www 用户magedu 已创建,家目录为/www ! [root@centos6 ~]#bash usermagedu.sh magedu /www 用户magedu 已存在! [root@centos6 ~]#id magedu uid=2005(magedu) gid=2005(magedu) groups=2005(magedu) [root@centos6 ~]#tail -1 /etc/passwd