Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to immediatley flush output

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
I have a shell script that processes information in a for loop.
The loop has an echo statement that displays each record. The problem is that the output is displayed when the for loop and script end.
I would like the output of each line to display to the screen during the loop.

How do I flush the output and have it echo the data to the screen on the fly?
 
What is your actual code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Heres a simplified version

for row in `traceroute $1 | tr " " "~"`
do
output=`echo $row`
echo "$output <br>"
done

The above script will display the results after the script is complete.
I want it to display each line as it is retrieved BEFORE the script ends.

How?
 
What about this ?
echo "$output <br>" [!]>/dev/tty[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Wow! Good try but doesnt seem to work. I didnt even think of that.
Any other ideas?
 
OMG!! I found it.

Because I am using quotes in my echo statement, it causes the output to buffer.

This works, no buffering:

for row in `traceroute $1 | tr " " "~"`
do
echo $row
echo \<br\>
done
 
It just cant be done.

This is why:

for row in `traceroute $1`
do
echo $row
done

the 'traceroute $1' must finish before the loop is started.
Its buffering the command output NOT the loop output.

 
And what about this ?
traceroute $1 | while read row
do
output=`echo $row | tr " " "~"`
echo "$output <br>" >/dev/tty
done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top