Simple shell-script example and shell-script example

Source: Internet
Author: User

Simple shell-script example and shell-script example

#! /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 "# use date create fileread-p" please input your filename: "fileuserfilename =$ {fileuser: -"filename"} # use date get the filenamedate1 =e1 (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 =2 {filename }$ {date2} file3 =3 {filename }$ {date3} touch "$ file1" touch "$ file2" touch "$ file3" # conditional read-p "please input (Y/N): "ynif [" $ yn "=" Y "] | [" $ yn "=" y "]; then echo "OK continue" exit 0 fiif ["$ yn" = "N"] | ["$ yn" = "n"]; then echo "OK continue" exit 0fi # case 2 if [conditional attention]; then content else content fi #3 if [conditional attention]; then content elif [conditional attention]; then content else content fi # Use case... esac determines the case $ variable name in "first variable content") program segment; "second variable content") program segment ;;*) program Section (excluding the content of the first and second variables) exit 1; esac # example case $1 in "one") echo "This is one"; "two ") echo "this is two"; "three") echo "This is three"; *) echo "no number ";; esac # Use the function (shell script is executed from top to bottom, from left to right, so the function must be written in the front of the program) function printit () {echo-n "Your choice is "}

 

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.