Shell script Beginner's Exercise Chapter

Source: Internet
Author: User
Tags case statement

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.