1

I'd like to create a bash function like this:

acmcom source.cpp output

It's supposed to do the same thing as:

g++ -g -O2 -std=gnu++14 -static source.cpp -o output

But I couldn't find anything on how to do this in Ubuntu using bashscr file. How can I define this function for further usages?

1

If you want to define a function, you can add the following lines to your ~/.bashrc:

acmcom(){
    echo g++ -g -O2 -std=gnu++14 -static "$1" -o "$2" > acmcom
}

Save the file, open a new terminal and you can now run:

acmcom  source.cpp output
1
  • Well what I wanted came with some small changes: acmcom() { g++ -g -O2 -std=gnu++14 -static "$1" -o "$2" } I didn't want it echoed. I needed it to be executed. But thanks :) – Mohammed Farahmand Aug 5 '17 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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