Linux-shell 练习题(一)

时间:2023-02-27 09:33:27

1、实现批量添加20个用户,用户名为user1-20,密码为user+123

#!/bin/bash

count=$1

if [ -n "$count" ]
then 
    for ((i=1;i<=$count;i++))
    do
    useradd -d /home/user_$i -s /bin/bash user_$i;
    echo user_"$i"123 |passwd --stdin user_$i;
   done
else
    echo "$count is empty"
fi

2、100个数相加,最大值,最小值

#!/bin/bash
sum=0
for i in `seq 0 1 99`
do
    echo ""$i""
    read -p "请输入数字" n
    a=$n
    sum=$[$sum+$n]
done
echo "最大值"
echo ${a}|sed 's//\n/g'|sort -r|sed -n '1'p
echo "最小值"
echo ${a}|sed 's//\n/g'|sort -n|sed -n '1'p
echo $sum
~