Automatic generation of basic framework scripts for C, C + +, Shell programs

Source: Internet
Author: User
Tags egrep

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

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.