Skip to main content
2 of 2
added 48 characters in body
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Assuming the contents of your input file is properly quoted (in the case where any of the arguments contain spaces, tabs, or newlines), then you may use xargs like so:

xargs -n 3 ./script.sh <arg_list.txt

This reads three arguments from the input at a time and calls your script with them.

A group of three arguments don't need to be listed on the same line in the input file, xargs will read three arguments and call your script with them, regardless of whether they are on the same line or spread across two or three lines.

Example (using a printf command in place of a script):

$ cat file
/path/to/file1.gz /path/to/file2.gz output_name1
/path/to/file1.gz /path/to/file2.gz output_name1
'/path/to/file 1.gz' /path/to/file2.gz output_name1
/path/to/file1.gz /path/to/file2.gz output_name1
/path/to/file1.gz
/path/to/file2.gz output_name1
/path/to/file1.gz /path/to/file2.gz output_name1
$ xargs -n 3 printf 'Arg1: "%s", Arg2: "%s", Arg3: "%s"\n' <file
Arg1: "/path/to/file1.gz", Arg2: "/path/to/file2.gz", Arg3: "output_name1"
Arg1: "/path/to/file1.gz", Arg2: "/path/to/file2.gz", Arg3: "output_name1"
Arg1: "/path/to/file 1.gz", Arg2: "/path/to/file2.gz", Arg3: "output_name1"
Arg1: "/path/to/file1.gz", Arg2: "/path/to/file2.gz", Arg3: "output_name1"
Arg1: "/path/to/file1.gz", Arg2: "/path/to/file2.gz", Arg3: "output_name1"
Arg1: "/path/to/file1.gz", Arg2: "/path/to/file2.gz", Arg3: "output_name1"
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k