I'm trying to capture output and seeing strange behavior. Some output will only show if no redirection is used. Can be replicated reliably with this docker example:
FROM alpine
RUN apk add git
RUN \
echo "echo \"----NO REDIRECT:\" && no_redirection=\$(git clone http://github.com/srfrnk/jabos-examples.git /tmp1)" >> test &&\
echo "echo \"----NO REDIRECT CAPTURED: \${no_redirection}\"" >> test &&\
echo "echo \"----REDIRECT:\" && redirection=\$(git clone http://github.com/srfrnk/jabos-examples.git /tmp2 2>&1)" >> test &&\
echo "echo \"----REDIRECT CAPTURED: \${redirection}\"" >> test &&\
cat test &&\
chmod +x test
ENTRYPOINT [ "/bin/sh","-c"]
CMD ["./test"]
This is essentially running the following script in a container:
echo "----NO REDIRECT:" && no_redirection=$(git clone http://github.com/srfrnk/jabos-examples.git /tmp1)
echo "----NO REDIRECT CAPTURED: ${no_redirection}"
echo "----REDIRECT:" && redirection=$(git clone http://github.com/srfrnk/jabos-examples.git /tmp2 2>&1)
echo "----REDIRECT CAPTURED: ${redirection}"
So there are two cases running git
- one with redirection and one without. Both output are captured into a variable which is then printed.
If you build and run this (docker build . -t test && docker run -it test
) you can see the following output:
----NO REDIRECT:
Cloning into '/tmp1'...
warning: redirecting to https://github.com/srfrnk/jabos-examples.git/
remote: Enumerating objects: 195, done.
remote: Counting objects: 100% (195/195), done.
remote: Compressing objects: 100% (137/137), done.
remote: Total 195 (delta 106), reused 122 (delta 44), pack-reused 0
Receiving objects: 100% (195/195), 40.92 KiB | 498.00 KiB/s, done.
Resolving deltas: 100% (106/106), done.
----NO REDIRECT CAPTURED:
----REDIRECT:
----REDIRECT CAPTURED: Cloning into '/tmp2'...
warning: redirecting to https://github.com/srfrnk/jabos-examples.git/
P.S. This isn't a docker thing - happens in bash on my Ubuntu box as well. I used docker to have an environment agnostic example.
So my question is where does the output after warning: ...
go to and how can I redirect/capture that?