Linux: Run command on a batch of files, with matching output files

bashbatchcommand linelinuxscript

A simple task: given a directory of files and a command that takes one file as input and produces one file as output, I want to process all the files in a directory at once and output them with corresponding matching names (with new extensions).

So if the command would normally be:

convert -input sourceFile.ext -output destFile.out

I want to process a folder with

file1.ext, file2.ext, etc.

and produce in the same directories the files

file1.out, file2.out, etc.

Is there any way to do this in terminal without writing a bash script? I'm not very familiar with scripting, so any simple solution would be appreciated.

Best Answer

Without using basename:

for file in *.ext; do convert -input "$file" -output "${file/%ext/out}"; done

See http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion

Related Question