简体   繁体   中英

Use the output of a cat command in execution (bash)

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?

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 .

使用xargs

xargs -n 1 ./script < test.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM