Sami Şimşekli Sami Şimşekli - 4 months ago 20
C Question

Same executable name with c file after compilation

I want to compile several c files and I want to have executables whose names are same as the c file's names i.e I have trial1.c. How can I have trial1.out without using -o trial1 option?

Answer

Do you want something like this?

for i in *.c; do gcc ${i::1}.c -o ${i::1}.out; done

Or, if you are interested on just knowing if they compile successfully:

for i in *.c; do gcc $i 2>/dev/null && echo "$i : OK" || echo "$i : FAIL"; done