First, hello to stackoverflow community. I have learnt a lot thank to very clear questions and professional replies. I never needed to ask question because there is always someone who has asked the same question before.
But not today. I haven't found any solution to my problem, and I beg for your help.
I need to process the output of a function line by line in order to update a log online. I am working with bash
.
The following block works pretty well:
convertor some parameters | while read line
do
if [ "${line:0:14}" != "[informations]" ]
then
update_online_log "${line}"
fi
done
But convertor
may exit with different status. And I need to know what was the exit status. The code below doesn't work as it gives me the exit status of the last executed command (update_online_log
).
convertor some parameters | while read line
do
if [ "${line:0:14}" != "[informations]" ]
then
update_online_log "${line}"
fi
done
exit_status=$?
The code below should work (I haven't tried it yet):
convertor some parameters > out.txt
exit_status=$?
while read line
do
if [ "${line:0:14}" != "[informations]" ]
then
update_online_log "${line}"
fi
done < out.txt
rm out.txt
But if I use this, the online log will be updated at the end of the conversion. Conversion may be a very long process, and I want to keep users updated while the conversion is in progress.
Thank you in advance for your help.