H
H
Helig2020-12-05 18:18:53
linux
Helig, 2020-12-05 18:18:53

How to create custom command in linux with argument?

I want to create my own command for compiling and then running a c++ program.

Now it consists of two steps:
$g++ program.cpp -o program //compile
$./program //run

I tried to create with alias but no success
$alias compile='g++ $?.cpp -o $? ';'./$?'

And I would like to just enter the compile <file name> command and not take a steam bath.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xibir, 2020-12-05
@Helig

function compile()
{
    && g++ $1.cpp -o $1 && ./$1
}

A
Anubis_I, 2020-12-06
@Anubis_I

use make utility and makefile

V
Vladimir Korotenko, 2020-12-05
@firedragon

See operators || && they provide either another operation or a serial

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question