繁体   English   中英

在执行中使用cat命令的输出(bash)

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

我想一个简单的问题..但是我用谷歌找不到它。

我有一个文件test.txt ..它包含;

blah
blah2
blah3

我想做的是

cat test.txt然后执行;

./script blah
./script blah2
./script blah3

但是我想一站式做。.什么是最好的方法? 我知道使用&&是一个选项..但是也许有更好的方法来传递字符串?

不需要cat (或其他任何外部工具)。 就像是:

while read line; do ./script "$line"; done < test.txt

使用内置的shell read来完成您想要的工作。

如注释中指出的那样,这假定您与脚本位于同一目录中。 如果不是,请将./script替换为path/to/script

使用xargs

xargs -n 1 ./script < test.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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