Shell--常用变量

1、判断是不是月底最后一天?
#!/bin/bash
((`date '+%d'` == 1 || `date '+%d' -d tomorrow` == 1))
echo $?
2.生成随机字符
#!/bin/bash
function Rand_Digit_Pass(){
    digit_pass_len=5 #定义密码长度
    digit_seq=(0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9) #数字范围
    i=1
    digit_len=${#digit_seq[@]} #数组变量长度
    ###生成数字密码
    while [ "$i" -le "$digit_pass_len" ]
    do
        digit_rand[$i]=${digit_seq[$((RANDOM%digit_len))]} #存入数组digit_rand中
        let "i=i+1"
    done
    for digit_pass in ${digit_rand[@]}
    do
        echo -n "$digit_pass"
    done
}
function Rand_Str_Pass(){
    str_pass_len=3
    str_seq=(a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
    j=1
    str_len=${#str_seq[@]}
    ###生成字符密码
    while [ "$j" -le "$str_pass_len" ]
    do
        str_rand[$j]=${str_seq[$((RANDOM%str_len))]}
        let "j=j+1"
    done
    for str_pass in ${str_rand[@]}
    do
        echo -n "$str_pass"
    done
}
RandPass=$(Rand_Digit_Pass)$(Rand_Str_Pass)
echo $RandPass

 

posted @ 2020-12-27 21:23  Buster_Hsueh  阅读(51)  评论(0编辑  收藏  举报