Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Is there anyway to compile many files by a single instruction in Linux bash?

For example, in Linux, gonna compile 3 files "test1.c", "test2.c" and "test3.c" separately to "test1", "test2" and "test3", is there a way using wildcard or pipe to do it by one line bash instruction?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There's not really such a thing as a "bash instruction", and even if you say "bash command", then gcc isn't really such a thing either because it is not intrinsically related to, or a part of bash. It is a separate binary/program that can be run under any shell, such as sh, ksh, ash, dash or even tcsh.

Assuming you mean one line, you can do:

gcc prog1.c -o prog1 & gcc prog2.c -o prog2 & gcc -o prog3 prog3.c

You can equally do that in a loop as William was suggesting:

for f in test?.c; do gcc "$f" -o "${f%.c}" &  done

IMHO though, the easiest is with GNU Parallel:

parallel gcc {} -o {.} ::: test?.c

There are those who will rightly say that GNU Parallel is not part of POSIX, but, to be fair, you didn't mention POSIX in your question. So, if POSIX-compliance is an issue, you may choose to avoid this suggestion.


As suggested in the comments, a Makefile would be even better, So if you create a file called Makefile with the following contents:

all: test1 test2 test3

You can simply run:

make

and all three programs will be compiled, only if necessary, i.e. if you have changed the source file since last compiling. Or, if you want to use all those cores that you paid Intel so handsomely for, you can do them in parallel with:

make -j
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda