1. 循環添加10個用戶:
bash
#!/bin/bash
#
for i in {1..10}; do
if id user$i &> /dev/null; then
echo "user$i exists."
else
useradd user$i
echo user$i | passwd --stdin user$i &> /dev/null
echo "add user user$i finished."
fi
done
2. 循環刪除10個用戶:ide
#!/bin/bash
#
for I in {1..10}; do
if id user$I &> /dev/null; then
userdel -r user$I
echo "Delete user$I finished."
else
echo "user$I not exist."
done
it