3

This question already has an answer here:

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

marked as duplicate by Mikel, slm Sep 13 '14 at 1:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    You should use make, this is its jobs – cuonglm Sep 12 '14 at 19:52
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.