vii

 

#!/bin/bash

if [ $# -eq 0 ]
then
    vi
    exit
fi

if [ $# -ge 2 ]
then
    echo "参数太多了!"
    exit
fi


if [ -e $1 ] # 文件已存在,一律直接打开不作任何处理
then
    vi $1
    exit
else
    suffix=`echo "$1" | sed 's/^.*\./\./'`

    # 如果是C语言程序,搞个模板开始编辑
    if [ $suffix = ".c" ]
    then
        cp /bin/sample.c $1
        vi $1 +15
        exit

    # 否则,直接编辑空文件
    else
        vi $1
        exit
    fi
fi

example.c

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>

int main(int argc, char **argv)
{
    return 0;
}

 

相关文章:

  • 2021-11-04
  • 2022-02-08
  • 2021-07-28
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
猜你喜欢
  • 2021-04-20
  • 2021-07-26
  • 2021-06-03
  • 2021-05-22
  • 2022-02-18
  • 2022-01-22
  • 2021-11-09
相关资源
相似解决方案