If I have a list of files say file1
... file20
, how to I run a command that has the list of files as the arguments, e.g. myccommand file1 file2 ... file20
?
If your list is in your argument vector -- that is to say, if you were started with:
./yourscript file1 file2 ...
then you'd run
mycommand "$@"
If your list is in an array:
mycommand "${my_list_of_files[@]}"
If your list is in a NUL-delimited file:
xargs -0 -- mycommand <file_with_argument_list
If your list is in a newline-delimited file (which you should never do for filenames, since filenames can legitimately contain newlines):
readarray -t filenames <file_with_argument_list
mycommand "${filenames[@]}"
If by "list", you just mean that you have a sequence of files:
mycommand file{1..20}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With