为学习APUE(Unix环境高级编程)偷懒,而写的脚本,基本上相当于一个简单的工程创建脚本了

来源:互联网 发布:汽车租赁管理系统java 编辑:程序博客网 时间:2024/04/26 03:55
 首先我单独建了一个目录用来保存学习时需要的目录,将此脚本拷贝到这个目录下面,以后每次以一个参数运行脚本,就会自动创建目录,cpp文件,makefile文件,需要做的就是进入此目录,然后修改cpp文件,然后make,enjoy it!呵呵,说实话,自从学习了bash以后,才越来越觉得linux并不是一个复杂难用的系统。

D:/ubuntu/apue/ctapue.sh.html 1 #!/usr/bin/env bash
 2 dir=apue$1
 3 file=${dir}/apue${1}.cpp
 4 makefile=${dir}/Makefile
 5
 6 if [ -d ${dir} ]
 7 then
 8     echo "the path ${dir} is exist."
 9     exit 1
10 else
11     mkdir ${dir}
12 fi
13
14 # Create the src file
15 cat >${file} <<end-of-file
16 #include <stdio.h>
17 #include "../apue.h"
18
19
20 int main(int argc, char* argv[])
21 {
22
23
24     exit(0);
25 }
26
27 end-of-file
28
29 # Create the makefile
30 cat >${makefile} <<end-of-makefile
31 src=apue${1}.cpp
32 ob=test
33 /${ob} : /${src}
34     g++ -Wall -g -o /${ob} /${src}
35
36 end-of-makefile

原创粉丝点击