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?