I am running a simple script
#!/bin/bash
git fetch --all 2> stderr.txt
echo "Errorcode $?"
cat -n stderr.txt
echo Sleeping
sleep 1
cat -n stderr.txt
The strange point is the conclusion
Fetching origin
Errorcode 1
1 fatal: Couldn't find remote ref HEAD
2 error: Could not fetch origin
Sleeping
1 fatal: Couldn't find remote ref HEAD
2 error: Could not fetch origin
3 fatal: The remote end hung up unexpectedly
And how can I clear the output and still have access to the error code?
I tried it with stdbuf -o0 -e0, but no luck.
Cleaning works with tee, but then the error code is lost.
git fetch --all 2>&1 | tee stderr.txt > /dev/null
Note:
- An error is expected in this scenario.
- The problem also occurs without stderr redirection.
- I used to git version 2.11.0.
source
share