rahul
rahul

Reputation: 6487

Shell Scripting: read input from command output

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)

Upvotes: 0

Views: 112

Answers (2)

Bruce K
Bruce K

Reputation: 769

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

Upvotes: 1

cnicutar
cnicutar

Reputation: 182619

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

Upvotes: 2

Related Questions