read命令交互式接收参数,来选择删除或者添加用户:
#!/bin/bash
#
# Date: 2017-12-12
# Author: Liemer_Lius
read -p "Please input your choice(add|del): " CHOICE
if [ $CHOICE == 'add' ]; then
for i in user{1..3}; do
if id $i &> /dev/null; then
echo "User already exist. Skip..."
continue
else
useradd -M -s /sbin/nologin $i
echo "Add user $i finished."
fi
done
elif [ $CHOICE == 'del' ]; then
for i in user{1..3}; do
if ! id $i &> /dev/null; then
echo "No such user $i. Skip..."
continue
else
userdel -r $i &> /dev/null
echo "Delete user $i finished."
fi
done
else
echo "Wrong option. Usage: `basename $0` del|add"
fi
发表回复
要发表评论,您必须先登录。