簡體   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