閑逛中看到如下幾個(gè)bash題目,于是手癢

1、使用for循環(huán)在目錄下通過(guò)隨機(jī)小寫(xiě)10個(gè)字母加固定字符串Xman批量創(chuàng)建10個(gè)html文件,名稱(chēng)例如為:
# sh randfile.sh
# ll
total 4
-rw-r--r-- 1 root root 0 Feb 17 16:07 cxriwsivclXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 cxypjcpazqXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 fvkdxxluouXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 mahnrlhyduXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 omhxsjftubXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 pyevqsxrfnXman.html
-rw-r--r-- 1 root root 216 Feb 17 16:06 randfile.sh
-rw-r--r-- 1 root root 0 Feb 17 16:07 rcrecpovdhXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 vmjzedrtapXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 worlmhciqjXman.html
-rw-r--r-- 1 root root 0 Feb 17 16:07 xietooufrmXman.html
實(shí)現(xiàn)如下:
#!/bin/bash
#
arr=( 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 )
for((j=1;j<=10;j++));do
str=
for((i=1;i<=10;i++));do
str="$str\${arr[$[$RANDOM%26]]}"
done
touch $(eval echo $str)Xman.html
done2、將以上文件名中的Xman全部改成gril(用for循環(huán)實(shí)現(xiàn)),并且html改成大寫(xiě)。
#!/bin/bash for file in *.html ; do mv $file $(echo $file | sed 's/Xman.html/gril.HTML/') ; done
結(jié)果:
[root@tvvmq40030 t]# ll
total 4
-rw-r--r-- 1 root root 0 Feb 17 16:07 cxriwsivclgril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 cxypjcpazqgril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 fvkdxxluougril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 mahnrlhydugril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 omhxsjftubgril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 pyevqsxrfngril.HTML
-rw-r--r-- 1 root root 216 Feb 17 16:06 randfile.sh
-rw-r--r-- 1 root root 0 Feb 17 16:07 rcrecpovdhgril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 vmjzedrtapgril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 worlmhciqjgril.HTML
-rw-r--r-- 1 root root 0 Feb 17 16:07 xietooufrmgril.HTML
3、bash for循環(huán)打印下面這句話(huà)中字母數(shù)不大于6的單詞(昆侖萬(wàn)維面試題)。
I am oldboy teacher welcome to oldboy training class.
結(jié)果如下:
[root@tvvmq40030 t]# sh pr.sh
I
am
oldboy
to
oldboy
class.
實(shí)現(xiàn):
#!/bin/bash
for i in I am oldboy teacher welcome to oldboy training class. ; do
[[ ${#i} -le 6 ]] && echo $i
done4、請(qǐng)用shell或Python編寫(xiě)一個(gè)等腰三角形(triangle.sh),接收用戶(hù)輸入的數(shù)字。
例如:
triangle.sh 另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站名稱(chēng):bash實(shí)戰(zhàn)-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://chinadenli.net/article16/dspogg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、域名注冊(cè)、自適應(yīng)網(wǎng)站、微信小程序、企業(yè)建站、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容