作业

1、要求添加一个用户newuser,如果其已经存在则显示”The user USERNAME is exists”,如果存在,则添加之,并将其密码设置为”P@ssw0rd

#!/bin/bash
#
username=newuser1
if ! id $username &> /dev/null;
        then adduser $username
        echo $username | passwd --stdin "P@ssw0rd" &> /dev/null
        echo "Add user $username sucessfully."
        else "The user is exists."
fi
exit

2、写一个脚本,如果某路径不存在,则将其创建为目录,否则显示其存在,并显示内容类型

#!/bin/bash
#
path="/tmp/testdir"
if [ ! -e $path ];then
        if [ ! -d $path  ];then
                mkdir $path
                echo "Make directory $path sucessfully."
                else  echo "$path has been exists."
        fi 
else echo "$path has been exists."
fi