0

Why does the following code gives only first line from ps -eaf output in ps.out?

while read line; 
do
   echo $line>ps.out; 
done < <(/bin/ps -eaf)
rahul
  • 6,447
  • 3
  • 31
  • 42

2 Answers2

2

You are truncating the file each time so you only get the last line. You probably want >> instead of >.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
1

Or redirect the entire loop output by putting ">ps.out" after the "done".

Bruce K
  • 749
  • 5
  • 15