Issue
I have a file as a list with newlines separating each argument.
thing1
thing2
thing3
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?
Solution
You can do that with a while
loop which read
s 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