Passing list as arguments to a command


I have a file as a list with newlines separating each argument.


I want to run a command with each item from the list separately so it’d run as

do thing1
do thing2
do thing3

And do them in order to not overload the system as each individual command would be fairly intensive. How would I go about doing this?


You can do that with a while loop which reads the file.

Something like

while IFS= read -r arg; do
    your_command "$arg"
done < "Your_file"

The < redirection will send the content of "Your_file" to the while loop, which will read each line, and assign it’s value to the $arg variable.

Answered By – mivk

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published