S32.shell脚本每日一练

63.打印杨辉三角形

root@ubuntu2004:~# cat yanghui.sh 
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2021-10-22
#FileName:      yanghui.sh
#URL:           raymond.blog.csdn.net
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
yanghui(){
    
    
    tmp=$1
    i=0
    while [ $i -ne `expr $tmp + 1` ];do
        if [ $i -eq $tmp ]||[ $i -eq 0 ];then
            echo -n 1  
        else
            echo -n $(expr $2 + $3)  
            shift
        fi
        echo -n " "  
        i=`expr $i + 1`
    done
}
if [ $# -ne 1 ];then
   read -p  "enter the Max number:"  COUNT
else
    COUNT=$1
fi
i=0
while [ $i -ne  $COUNT ];do
    tmp=(`yanghui $i ${
     
     tmp[*]}`)
    echo ${tmp[*]}  
    i=`expr $i + 1`
done 

root@ubuntu2004:~# bash yanghui.sh 
enter the Max number:5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

root@ubuntu2004:~# bash yanghui.sh 
enter the Max number:10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

64.批量创建用户

[root@rocky8 ~]# vim eval_createuser.sh
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2021-10-22
#FileName:      eval_createuser.sh
#URL:           raymond.blog.csdn.net
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
n=$#
[ $n -eq 0 ] && {
    
     echo "Usage: `basename $0` username..." ; exit 2; }

for i in `eval echo {
     
     1..$n}`;do
    user=${
    
    !i}
    id $user &> /dev/null && echo $user is exist || {
    
     useradd $user; echo $user is created; }
done

[root@rocky8 ~]# bash eval_createuser.sh tom jack bob
tom is created
jack is created
bob is created

猜你喜欢

转载自blog.csdn.net/qq_25599925/article/details/127243185