I would like to have an alias for the following code:-

g++ *.cc -o * `pkg-config gtkmm-3.0 --cflags --libs`;

but I want that when I enter the alias it should be followed by the file name *.cc and then the name of the compiled program *.

for example:

gtkmm simple.cc simple

should run

g++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`

1 Answer 1


What you need isn't an alias, but a function. Aliases do not support parameters in the way you want to. It would end just appending the files, gtkmm simple.cc simple would end like:

g++ -o `pkg-config gtkmm-3.0 --cflags --libs` simple.cc simple

and that's not what you try to achieve. Instead a function allows you to:

function gtkmm () {
    g++ "$1" -o "$2" `pkg-config gtkmm-3.0 --cflags --libs`

Here, $1 and $2 are the first and second arguments. $0 is the caller itself:

gtkmm simple.cc simple
$0    $1        $2

You can test the function using echo.

You can find more functionalities about functions in the Bash online manual.

  • Works fine just as expected May 24, 2015 at 16:33
  • 1
    Better yet, create a Makefile and run make...
    – lcd047
    May 24, 2015 at 16:36
  • @lcd047 for one shot commands to test stuff creating a Makefile can be overkill.
    – Braiam
    May 24, 2015 at 16:41
  • but as i do random coding and i ve got a lot of different files across directories I don't need a makefile cause i would create a lot of make files for stand alone cpp files May 24, 2015 at 16:44

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