Operation and Maintenance Enterprise Interview Question 2 Create 10 "ten random letters_test.html" files

Practical programming written test questions for Linux operation and maintenance (19 questions)

Enterprise interview question 2 :
Use the for loop to create 10 html files in batches in the /tmp/www directory with 10 random lowercase letters plus a fixed string test, the names are for example:

-243-[root@vm]21:34 /tmp/www # ls
cqhofapwqf_test.html  fkcprqvoyu_test.html  ntybtjgmrp_test.html  ryxixeexlt_test.html  uafijmxdnl_test.html  vwzcpcyduz_test.html

sh script:

#!/bin/bash
#
#
#Randomly generate 10 lowercase letters, add fixed characters test to create 10 html files in batches
#Example: asdhjkwevd_test.html
#
#version 0.1

bname='_test.html'
declare -a randwords
for((i=0;i<=9;i++)){
    randwords[$i] =`openssl rand -base64 48 | sed  ' s@[^[:lower:]]@@g ' | cut -c - 10 ` #sed is adjusted to all lowercase letters, cut intercepts 10 characters
     touch ${randwords[$i]}$bname
    }
openssl rand -base64 --> generate random numbers
sed 's@[^[:lower:]]@@g' --> remove non-lowercase letters
cut -c -10 --> take 10 characters

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325234909&siteId=291194637
Recommended