Question

The standard way to capture command output in Bourne shell is to use the $() syntax:

output=$(mycommand)

For commands that have a lot of output, however, this requires the shell allocate memory for the whole thing as one long string. I'd prefer to find something that does the moral equivalent of the Unix C function popen, to get a new file descriptor I could read from:

newfd=popen(mycommand)
while read -u $newfd LINE; do
  #process output
done

Is this even possible?

Was it helpful?

Solution

#!bash
ls | while read X
do 
    echo  $X is a directory entry
done

Replace 'ls' with the command of your choice

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top