renshanshan 发表于 2018-8-28 09:13:34

自动生成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$1 > $1
页: [1]
查看完整版本: 自动生成C、C++、shell程序基本框架脚本