0

I need to execute a command for a list of files that convert them from one format to another, say:

conv -option MYOPTION file1 > file1.output

However, I have a list of files in a folder, say:

file1, file2, …, fileN

I need a script that runs such command for each and every file, something like:

script.sh MYOPTION *.TXT

I did some research and found something like:

for f in *; do
  echo "$f"
done

Now the problems are:

  1. How do I get the "list of files", in my example, *.TXT, into the script so it's mapped to the list of files? (ie. no hardcoded * in the script, it should work also if I only specify one single file)
  2. How do I invoke system command in a script? Something like conv -option $1?

Thanks!

hzxu
  • 4,650
  • 7
  • 52
  • 86
  • `conv -option "$f"`. Why do you think it would be different from the way you invoke `echo`? – Barmar Jan 16 '20 at 20:31
  • Oh thanks! So I can put the command call just like `echo` inside a script? I didn't realise it's not a script keyword. – hzxu Jan 16 '20 at 20:32
  • A script is just shell commands put into a file and executed automatically. – Barmar Jan 16 '20 at 20:39

0 Answers0