开发者

How can I read standard input in a loop in bash, and then append the text to a file?

开发者 https://www.devze.com 2023-01-03 05:50 出处:网络
Say I have a bash script as follows while read $f; do cat $f >>开发者_JAVA百科 output.txt; echo \"aaa\" >> output.txt;

Say I have a bash script as follows

while
 read $f;
do
 cat $f >>开发者_JAVA百科 output.txt;
 echo "aaa" >> output.txt;
done

Yet the second echo statement isn't executed. At all. What am I doing wrong?

I'm running this via

tail -f /var/log/somelog | ./script.sh

$f should not be empty. It's only supposed to output when tail notices a change in the file.


The variable $f is probably empty, and your script is hanging on a call to cat with no arguments. Did you want to say

while read f

instead of

while read $f

?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号