Shell script (auto-populate function template)

Source: Internet
Author: User

Recently many students watching my video tutorial, the VII is curious about the goods, VII is a relative of VI? Why use it to create a new program to automatically populate the program framework code? Today, we'll have a steak.

In fact, VII is a script I wrote, with VI not half a dime relationship, just borrow this name only. So what does this script look like? Look


Now listen to me in detail for you to parse the above code, to see the 1th line:

#!/bin/bash

This is the format of the shell script, nothing good to say.


Look again at 第3-6 line:

If [$#-eq 0]

Then

Vi

Fi

This is the time to judge the implementation VII with no parameters, if not with parameters, then directly start VI


Look again at 第8-16 line:

If [$#-eq 1]

Then

Suffix= ' echo $ | Sed "s/\ (. *\) \ (\. \) $/\2/"'

if [$suffix! = ". C"] | | [-E $]

Then

VI $

Exit

Fi

Fi

This is in the case with only one parameter, such as VII hello.c or VII hello.txt, judge the file suffix suffix, if the suffix is not. C or the file itself already exists, then directly with VI Open. Otherwise, the file to be created must be a file that does not exist and the suffix is. c, and you can enter the following code.


Look again at 第19-28 line:

Sample= "/bin/sample.c"


if [!-e $sample]

Then

echo "$sample is not exist"

Exit

Else

CP $sample $

VI $

Fi

SAMPLE.C is a program framework template that writes the header file, the main function, and puts it under/bin. Directly CP the template file to the current directory and use VI to open the template.

Shell script (auto-populate function template)

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.