使用for循環在/clsn目錄下批量創建10個html文件,其中每個文件需要包含10個隨機小寫字母加固定字符串clsn,腳本內容:
[root@lry scripts]# cat make_file.sh
#!/bin/bash
##############################################################
# File Name: make_file.sh
# Created Time : 2018-06-26 20:32:33
# Description:
##############################################################
[ -d /clsn ] || mkdir -p /clsn
rpm -qa | grep pwgen &>/dev/null
if [ $? -eq 1 ]
then
yum install pwgen -y &>/dev/null
fi
cd /clsn &&\
for i in {1..10}
do
#File_Name = `uuidgen |tr "0-9-" "a-z"|cut -c 1-10`
File_Name2=`pwgen -1A0 10`
touch ${File_Name2}_clsn.html
done
bash這個腳本
[root@lry clsn]# ll /clsn
total 0
-rw-r--r-- 1 root root 0 Jun 26 20:55 aiyoaxaefu_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 chaimohphu_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 eewohseefu_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 meevaifugh_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 mopohseeje_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 soorooboch_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 yeonahceej_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 yiengahfoh_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 yupiweuzaz_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 zeipeiseiy_clsn.html
其中,[root@lry scripts]# rpm -qa | grep pwgenaa
[root@lry scripts]# echo $?
1
[root@lry scripts]# rpm -qa | grep pwgen
pwgen-2.07-1.el7.x86_64
[root@lry scripts]# echo $?
0
echo $0的值等於0表示成功狀態