1

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 Answers1

3

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.

Braiam
  • 35,991