What I want
My actual long term goal is bypassing all the output of a git process into another function (in order to make a progress bar - see my older question for more details about that).
What I've got so far
I thought my problem was solved after this question but it comes out now that only partially.
I have already figured out that git
- produces output only to
stderrby design - I had to use the
--progressoption ofgitin order to forcegitto really print out the progress.
Now if I run
#or also &> output.file
git clone --progress http://someRepo > output.file 2>&1
I can see the full progress e.g. by running at the same time in a second terminal
tail -f output.file
I get
Cloning into 'someRepo' ...
remote: Counting objects: 2618, done.
remote: Compressing objects: 100% (14/14), done.
Receiving objects: 4% (106/2618), 42.11 MiB | 5.67 MiB/s
which gets updated in realtime until finishing
Cloning into 'someRepo' ...
remote: Counting objects: 2618, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 2618 (delta 2), reused 12 (delta 1), pack-reused 2603
Receiving objects: 100% (2618/2618), 258.95 MiB | 5.71 MiB/s, Done.
Resolving differences: 100% (1058/1058), Done.
Checking connectivity ... Done.
So far so well.
My Problem
Now I do not want to put this output into a file anymore but rather bypass it into a function. So I tried
#or also |&
git clone --progress http://someRepo 2>&1 | {
while read -r line
do
# echo is for testing only
# later I want to pass this to another function
# EDIT: I added bypassed in order to see what is bypassed
echo "bypassed: ${line}"
done
}
But running it like this I only get as output displayed (EDIT: I added the bypassed: to the echo line in order to see how it gets passed.)
bypassed: Cloning into 'someRepo'
bypassed: remote: Counting objects: 2618, done.
remote: Compressing objects: 100% (14/14), done.
and only at the very end when the download finishes I get the rest all at once jumping to this output (EDIT: I added the bypassed: to the echo line in order to see how it gets passed.)
bypassed: Cloning into 'someRepo' ...
bypassed: remote: Counting objects: 2618, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 2618 (delta 2), reused 12 (delta 1), pack-reused 2603
Receiving objects: 100% (2618/2618), 258.95 MiB | 5.71 MiB/s, Done.
Resolving differences: 100% (1058/1058), Done.
bypassed: Checking connectivity ... Done.
So apparently the 5 lines of the progress block are all passed in at once .. maybe this is a problem for the pipe and the while loop?
So what am I missing? How to I have to run the command in order to get the output also "echoed" / bypassed into my function later in realtime just the same way the tail -f output.file gets updated in realtime?
EDIT
I also already tried stdbuf and even unbuffer as suggested here and here
stdbuf -i0 -o0 -e0 git clone --progress http://someRepo |& ...
stdbuf -oL git clone --progress http://someRepo |& ...
unbuffer git clone --progress http://someRepo |& ...
but this didn't change the output.