Reputation: 1181
Simple question I think.. but I couldnt find it with google..
I have a file test.txt.. it contains;
blah
blah2
blah3
What I want to do is;
cat test.txt and then execute;
./script blah
./script blah2
./script blah3
But I want to do it in one line.. What would be the best ways to do it.. ? I know using && is a option.. but maybe there are better ways to pass the string?
Upvotes: 2
Views: 8944
Reputation: 74595
No need for cat
(or any other external tool for that matter). Something like:
while read line; do ./script "$line"; done < test.txt
does what you want, using the shell builtin read
.
As pointed out in the comments, this assumes that you are in the same directory as the script. If not, replace ./script
with path/to/script
.
Upvotes: 5