Linux “echo -n” not being flushed

  • A+
Category:Languages

I have the following code:

while ...   echo -n "some text" done | while read; do   echo "$REPLY" >> file done 

but echo works only when used without "-n" flag. looks like when using -n, the output is not flushed/read by next while loop

How can I make sure that "some text" will be read even when not followed by EOL?


You can't distinguish between

echo -n "some text" 

and

echo -n "some t" echo -n "ext" 

so you need some kind of delimiting rule. Usually EOL is used for that. read supports custom delimiter via -d or can split based on number of chars via -n or -N. For example you can make read fire on each symbol:

echo -n qwe | while read -N 1 ch; do echo $ch; done 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: