linux c 程序框架,自动生成C、C++、shell程序基本框架脚本

自动生成C、C++、shell程序基本框架脚本,该脚本根据使用者给出的扩展名生成不同程序的框架,这大大节省了我们在编程过程中的重复输入基本框架的时间。

#!/bin/bash

declare -i cc_flag=0,c_flag=0,sh_flag=0

function main {

if [ $# -le 0 ];then

echo -e "\033[31mUsage: $0 \033[0m"

exit 1

fi

if [ -e $1 ];then

return 0

fi

# identify which template should be made accroding to the file suffix

if echo $1 | egrep ".*\.cc|cpp\>" &> /dev/null; then

cc_flag=1

elif echo $1 | egrep ".*\.c\>" &> /dev/null; then

c_flag=1

elif echo $1 | grep ".*\.sh\>" &> /dev/null; then

sh_flag=1

else

echo -e "\033[31mBad file! Not a C++_file or C_file or SH_file\033[0m";

fi

# accroding the flag to make template

if [ $cc_flag -eq 1 ];then

cat >> $1 <

#include

using namespace std;

int main(int argc, char *argv[])

{

return 0;

}

EOF

elif [ $c_flag -eq 1 ];then

cat >> $1 << EOF

#include

#include

#include

int main(int argc, char *argv[])

{

return 0;

}

EOF

elif [ $sh_flag -eq 1 ] ;then

cat >> $1 << EOF

#!/bin/bash

# date : `date`

EOF

fi

}

main $*

vim $1

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值