Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个只能通过管道调用的 Bash 脚本。我很好奇从管道中读取数据的最佳方式是什么?该命令将如下所示:
$ output_gen | process
我的脚本是过程。这不是家庭作业,而是一种学习练习。
当您的程序从管道接收数据时,它是通过标准输入接收的。要从标准输入读取,请使用read内置。这是一个例子:
read
我的程序:
while read -r line; do <something with "$line"> done
命令:
printf 'foo\nbar\n' | ./myprog