I started a for
loop in an interactive bash
session. For this question we can assume the loop was something like
for i in dir/*; do
program "$i"
done > log
The command takes a lot longer than expected and still runs. How can I see the current progress of the running for
loop.
Non-Solutions:
- Look at
log
.
Doesn't work because:program
is expected to run silently. You can think ofprogram
as a validator. If the loop completes without any output then I'm happy. - Stop the loop. Add some kind of progress indication (for instance
echo "$i"
). Start the loop again.
Doesn't work because: The loop already ran for hours. I don't want to throw away all the time and energy invested in the current run. I assume everything works fine. I'm just curious and want to know the current progress. - Ctrl+Z then
set -x; fg
Doesn't work because:bash
doesn't continue the loop when usingfg
. Afterfg
only the current/next command inside the loop will run, then the loop exits. You can try it yourself usingfor i in {1..200}; do printf '%s ' $i; /usr/bin/sleep 0.5; done
.