I know that the construct to capture stdout to a variable is var=$(...)
. However why does the following not work?
docker pull nginx
version=$(docker run --rm --entrypoint nginx nginx:latest -version)
echo $version
I found, however, adding 2>&1
to the second line above makes things work, ie:
version=$(docker run --rm --entrypoint nginx nginx:latest -version 2>&1)
Can someone help me by explaining why in this case we need to add the additional redirect?