#!/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