Linux – Run a command on every file in a directory, changing the output name


I need to compile all of the C files in a directory into seperate outputs… see example
gcc -Wall program1.c -o program1.out

How do I do this?

Best Answer

Use string manipulation:

for f in *.c; do gcc -Wall "$f" -o "${f%%.c}.out"; done

No need for complicated regular expressions or anything that's not a shell builtin here.