老男孩出的Shell编程企业面试题2:
1
2
3
4
5
6
|
[root@oldboyoldboy]
#sh/server/scripts/oldboy.sh
#ls
coaolvajcq_oldboy.htmlqnvuxvicni_oldboy.htmlvioesjmcbu_oldboy.html
gmkhrancxh_oldboy.htmltmdjormaxr_oldboy.htmlwzewnojiwe_oldboy.html
jdxexendbe_oldboy.htmlugaywanjlm_oldboy.htmlxzzruhdzda_oldboy.html
qcawgsrtkp_oldboy.htmlvfrphtqjpc_oldboy.html
|
我的Shell脚本如下:
#!/bin/bash
html_dir=/oldboy/
for htmlnum in 1 2 3 4 5 6 7 8 9 10
do
filename=`head -c 500 /dev/urandom | tr -dc a-z | head -c 10`_oldboy.html
if [ -d $html_dir ]
then
cd $html_dir
touch $filename
else
mkdir $html_dir
cd $html_dir
touch $filename
fi
done