gcc目录下所有文件

来源:互联网 发布:花儿知为谁红情劫大清 编辑:程序博客网 时间:2024/06/15 05:54

Bash综合应用gcc目录下所有文件

Use gcc to compile all C source file toobject file in one dir.

#!/bin/bash

 

for i in *.c

do

echo "$i"

echo `basename $i`

echo `basename $i.c`

gcc $i -o `basename $i .c`

done

 

Three echos are used to test how to handlefilename.

Basename command can get the file name inthe full path, and the second parameter “.c” is cutted suffix from the filename.

 

Touch three C files, and add main code inthem.

The print out will like this.

[nick@d01 compilec]$ ./compile.sh

1.c

1.c

1

2.c

2.c

2

3.c

3.c

3

 

原创粉丝点击