shell指令碼練習 每天乙個shell指令碼 7

2021-09-19 12:42:17 字數 1051 閱讀 5704

我的部落格都是依照自己淺薄的現有知識去寫的,好多時候寫完了部落格,去查詢答案,會發現很多更剪短更效率更好的答案。寫部落格是激勵我自己能堅持下去,讓我的頭腦不去懈怠,望共勉。

題目:

write a script five_dirs.sh that does these tasks:

– make a directory five

– make five subdirectories five/dir1 through five/dir5

– in each subdirectory, make four files, file1 through file4, such that file1 has one line

containing the digit 1, file2 has two lines, each containing the digit 2, …, and file4

has four lines, each containing the digit 4

涉及知識點:

1.建立資料夾

mkdir  dirname
2.建立檔案

touch filename
3.檔案內容寫入

echo content
4.for 迴圈 seq 使用

for i in `seq 5`

dodone

我自己的解決辦法:

#!/bin/bash

mkdir five

cd five

for i in `seq 5`

do mkdir$

for j in `seq 4`

dotouch $'/dir'$'/file'$

for k in `seq $j`

doecho $j >> $'/dir'$'/file'$

done

done

done

shell基礎練習 每天乙個shell指令碼 8

我的部落格都是依照自己淺薄的現有知識去寫的,好多時候寫完了部落格,去查詢答案,會發現很多更剪短更效率更好的答案。寫部落格是激勵我自己能堅持下去,讓我的頭腦不去懈怠,望共勉。題目 編寫指令碼,利用變數random生成10個隨機數字,輸出這個10數字,並顯示其中的最大值和最小值 知識點 random變數...

每天乙個shell指令碼(3)

每天乙個shell指令碼 3 題目 請按照這樣的日期格式 x xx xx 每日在 test目錄下生成乙個檔案 判斷目錄是否存在 例如今天生成的檔案為 2018 6 11.log,並且把磁碟的使用情況寫到到這個檔案中 需要知識 日期date函式 獲取 yyyy mm dd 日期格式 date y m ...

每天乙個shell指令碼(4)

習題 將下面這句話中字元數在6以內的單詞列印出來 bash also interprets a number of multi character options 涉及的知識點 迴圈遍歷該字串成每個字元,注 shell中的迴圈的跳出也是用continue和break。shell中的for迴圈規則 1...