The script generates frameworks for different programs based on the extensions given by the user, which saves us the time to repeatedly enter the basic frame during programming.
#!/bin/bashdeclare -i cc_flag=0,c_flag=0,sh_flag=0function main {if [ $# - le 0 ];then echo -e "\033[31musage: $0 <cpp_file_name | c_file_name | sh_file_name>\033[0m " exit 1fiif [ -e $1 ];then return 0fi# identify which template should be made accroding to the file suffixif echo $1 | egrep ".*\.cc|cpp\>" &> /dev/null; then cc_flag=1elif echo $1 | egrep ". *\.c\> " &> /dev/null; then c_flag=1elif echo $1 | grep ".*\.sh\>" &> /dev/null; then sh_flag=1else echo -e "\033[31mbad file! not a c++_file or c_file or sh_file\033[0m"; Fi# accroding the flag to make templateif [ $CC _flag -eq 1 ];thencat >> $1 <<eof#include <iostream>using namespace std;int main (int &NBSP;AC,&NBSP;CHAR&NBSP;**AV) { return 0;} eofelif [ $c _flag -eq 1 ];thencat >> $1 << eof# include <stdio.h> #include <stdlib.h> #include <string.h>int main (int &NBSP;AC,&NBSP;CHAR&NBSP;**AV) { return 0;} eofelif [ $sh _flag -eq 1 ] ;thencat >> $1 << eof #!/bin/bash# date : ' Date ' eoffi}main $*vim $1
This article from the "11219885" blog, reproduced please contact the author!
Automatic generation of basic framework scripts for C, C + +, Shell programs