I want to create a script that can be given 3 arguments: task, infile-type, outfile-type; and it should apply the task to each of such files in the folder. For example, I should be able to give command: convert png jpg
, and it should convert all png files to jpg in the folder. I should also be able to send options with task, enclosed in quotes, e.g.: "convert -o myoption" png jpg
I tried:
#! /bin/bash
for f in *.$2
do
$1 "$f" -o "${f%.$2}.$3"
done
Will above work or do I need to enclose $1 etc in {} or []? I have not tried it since, if erroneous, it may cause unpredictable damage to files. Thanks for your help.