Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda