Shell script Beginner's Exercise Chapter
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9F/7B/wKioL1mdXkfDFzntAAAXoHD3udQ741.png "title=" Images.png "alt=" Wkiol1mdxkfdfzntaaaxohd3udq741.png "/>
Script 1
Function: Create 10 1M files
[[email protected] script]# cat make_file.sh #!/bin/bash#for i in $ (seq 1);d o dd if=/dev/zero of=/data/test/test "${i } "bs=1m Count=1done
Script 2
Function: Remove ordinary files larger than 100K in the/data/test directory into/tmp directory
[email protected] script]# cat file_mv.sh #!/bin/bash#find/data/test-type f-size +100k | Xargs-i MV {}/tmp
Script 3
Function: Delete any character that contains test in the/tmp directory and size greater than 100K file
[email protected] script]# cat file_rm.sh#!/bin/bash#find/tmp-name "test*"-type f-size +100k | Xargs-i Rm-f {}
Script 4
Example of a For loop with Continue,break
[[email protected] script]# cat for.sh #!/bin/bash# for loop egsfor I in {1..10};d o if [[$I-eq 6]];then Echo "Six six Six" continue elif [[$I-eq 9]];then echo "Bye Bye 9" Break fi echo $Idone
Script 5
Simple While loop example
[[email protected] script]# cat while.sh #!/bin/bash# while loop egsnum=5while [[$NUM-gt 0]];d o echo $NUM let NUM -=1done
Script 6
Simple Until loop example
[[email protected] script]# cat until.sh #!/bin/bash# until Loop egs#num=5until [[$NUM-lt 0]];d o echo $NUM let NU M-=1done
Script 7
Case statement usage with positional parameters
[email protected] script]# cat case.sh #!/bin/bash#case loop egs#var=$1case $VAR Inneo) echo hacker; Sternberg) echo rigorous;; Michael) echo creative;; *) echo unknow;; Esac
Script 8
Function Functions Example
[email protected] script]# cat function.sh #!/bin/bash#function egs# #1st functionfunction hi () {echo "Hi,you is Beau Tiful! "} #sencond Functionhello () {ECHO-E "June Lei says\" Hello thank you\ ""}hihello
This article comes from "a bit of meaning!" "Blog, be sure to keep this provenance http://powermichael.blog.51cto.com/12450987/1958762
Shell script Beginner's Exercise Chapter