if语句
1、编写脚本/root/bin/createuser.sh,实现如下功能:使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
#!/bin/bash
#
#********************************************************************
#Author: luoqixiong
#QQ: 427822450
#Date: 2018-08-30
#FileName: createuser-if_73.sh
#URL: http://www.cnblogs.com/lqynkdcwy
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
read -p "Please input username: " UserName
#id $UserName &> /dev/null && echo "$UserName" is Already exist || { useradd $UserName ; id $UserName; echo "$UserName" created success; }
id $UserName &> /dev/null
if [ "$?" = 0 ] &> /dev/null;then
echo "$UserName" is Already exist
else
useradd $UserName
id $UserName
echo "$UserName" created success
fi
2、编写脚本/root/bin/yesorno.sh,提示用户输入yes或no,并判断用户输入的是yes还是no,或是其它信息
#!/bin/bash
#
#********************************************************************
#Author: Luo QiXiong
#QQ: 427822450
#Date: 2018-08-29
#FileName: yesorno_73.sh
#URL: http://www.cnblogs.com/lqynkdcwy
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
read -p "Please input yes or no: " ANS
if [[ $ANS =~ ^[Y|y]([E|e][S|s])?$ ]];then
echo "You Choose yes"
elif [[ $ANS =~ ^[N|n][O|o]?$ ]];then
echo "You Choose no"
else
echo "You input wrong"
fi
3、编写脚本/root/bin/filetype.sh,判断用户输入文件路径,显示其文件类型(普通,目录,链接,其它文件类型)
4、编写脚本/root/bin/checkint.sh,判断用户输入的参数是否为正整数