compilation - Linux - can you compile AND run a program in one terminal line? -


for example, program named program.c

g++ program.c -o programname ./programname 

is there way consolidate these 2 lines?

yes, write...

g++ program.c -o programname && ./programname 

which attempt run program if compilation succeeded.

for more general approach, write bash script..

#!/bin/sh g++ $1 -o $2 && ./$2 

then (provided it's on path, it's executable , it's called mycompile)...

mycompile program.c programname 

to make program available on path, can pop in bin directory or directory under echo $path. if don't wish that, open ~/.bashrc file , add parent directory path path="$path:your/new/dir" (keep in mind scripts in folder reachable).

ensure it's executable (check ls -l mycompile), if not, can add permission chmod +x mycompile.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -