编辑bash命令gcc编译并在一行中执行 [英] edit bash command gcc to compile and execute in one line
问题描述
我想知道这是否可能:如果您将 gcc filename.c
编译为
,您将编译 filename.c
位于 a.out
文件
中,如果您将 ./ a.out
您将执行该文件。
复合版本
gcc filename.c&& ./a.out
我想在bash_profile中编辑此命令,以便在一个简短的命令行中执行此操作。
gcc filename.c
执行此操作 gcc filename.c&& ./a.out
您可以声明一个函数:
gccrun(){
gcc$ 1&& ./a.out
}
请注意,如果某人使用完整路径到C文件作为参数?
Makefiles通常用于这种类型的东西。
a.out:file.c
gcc $<
运行:a.out
./a.out
make run
会运行 a.out
如果源自上次编译后已更改或不存在,则重新编译它。
I want to know if this is possible:
if you put gcc filename.c
you will compile filename.c
in a.out
file
and if you put ./a.out
you will execute the file.
The composite version it's
gcc filename.c && ./a.out
I want edit this command in bash_profile to do this in one short command line.
gcc filename.c
do this gcc filename.c && ./a.out
You can declare a function:
gccrun () {
gcc "$1" && ./a.out
}
Be careful, though: what if someone uses full path to the C file as a parameter?
Makefiles are usually used for this kind of stuff.
a.out: file.c
gcc $<
run: a.out
./a.out
make run
would run a.out
recompiling it if its source has changed since the last compilation or doesn't exist.
这篇关于编辑bash命令gcc编译并在一行中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!