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)