#!/usr/bin/bash
read -p "please input a username:" user
id $user &>/dev/null # id user 用户是否存在
if [ $? -ne 0 ];then
echo "no such user: $user"
exit 1
fi
read -p "Are you sure?[y/n]:" action
#if [ $action = "y" -o $action = "Y" -o $action = "YES" ];then #-o 或者
# userdel -r $user
# echo "$user is deleted"
#fi
case "$action" in
y|Y|yes|YES) # 集合
userdel -r $user
echo "$user is deleted"
;;
*)
echo "error"
;;
esac
#!/usr/bin/bash
#判断命令是否存在
command1=/usr/bin/ls
if command -v $command1 &>/dev/null;then
: #如果命令存在 则不执行任何操作
else
echo "yum -y install xx" #如果命令不存在 执行安装命令
fi