A simple example of shell-script

Source: Internet
Author: User

#!/bin/Bash#defind the Pathpath=/usr/Localexport Pathread-P"Please input your first name:"Firstnamereap-P"Please input your last name:"LastNameEcho-E"\nyour name is: $firstname $lastname"#useDateCreatefileRead-P"Please input your filename:"Fileuserfilename=${fileuser:-"filename"} #useDateGet the Filenamedate1=$(Date--Date='2 days ago'+%y%m%d) Date2=$(Date--Date='1 days ago'+%y%m%d) Date3=$(Date+%y%m%d) File1=${filename}${date1}file2=${filename}${date2}file3=${filename}${date3}Touch "$file 1"Touch "$file 2"Touch "$file 3"#条件判断式read-P"Please input (y/n):"ynif["$yn"=="Y"] || ["$yn"=="y"] ; Then    Echo "OK Continue"Exit0fiif["$yn"=="N"] || ["$yn"=="N"] ; Then    Echo "OK Continue"Exit0fi#第二种情况if[conditional judgment type]; ThencontentElsecontentfi#三if[conditional judgment type]; Thencontentelif[conditional judgment type]; ThencontentElsecontentfi#利用case ... esac judgment Case$ variable Nameinch   "content of the first variable") procedure paragraph;; "content of the second variable") procedure paragraph;; *) program segment (does not contain the contents of the first and second variables) exit1    ;;Esac#举例 Case$1 inch   " One")   Echo " This is one"   ;; " Both")   Echo " This is the"   ;; "three")   Echo "This is three"   ;; *)   Echo "No number"   ;;Esac#利用function功能 (shell script is executed from top to bottom, from left to right, so function functions must be written at the front of the program)functionPrintIt () {Echo-N"Your Choice is"}

A simple example of shell-script

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.