3

My ultimate goal is to simplify routine task of compilation and run.

Now I've following commands

 1. g++ foo.cpp -o foo --std=c++11
 2. chmod foo +x #this may be overkill
 3. ./foo

So, my question if this can be done like

compile foo

with alias or something like that


I've tried

alias compile='g++ $1.cpp -o $1 --std=c++11'

with no luck

1 Answers1

3

This is a job for a function not an alias. Example:

compile() {

    g++ $1.cpp -o $1 --std=c++11
    chmod +x $1
    ./$1

}

Voilà!

HTH, Cheers