我有一个名为 numbers.txt
的文件。在文件中我有从 1 到 1000 的所有数字。我有一个程序在 200 轮中插入 1 到 5。
我尝试了以下脚本:
while read p; do
echo $((p % 5 + 1))
done <numbers.txt
它按预期打印 200 中从 1 到 5 的数字。
现在我需要将输出重定向到程序的输入。我试过这个:
./my-program < while read p; do
echo $((p % 5 + 1))
done <numbers.txt
但它失败了一个错误:
syntax error near unexpected token `do'
如何使用循环中的输入运行 ./my-program
?
最佳答案
你可以尝试使用for循环 喜欢
for i in `cat numbers.txt`; do
echo $[ $i % 5 + 1 ]
done
关于linux - 将 shell 脚本的输出重定向到程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40565973/