If I run a command in a subshell, I can collect the stdout into a variable, such as:
var=$(echo 'hello world') echo $var
Will print 'hello world' as expected.
If I add colour and a new line, this too is ok:
var=$(echo "Text in \n\e[34mBlue") echo -e $var
Prints "Text in Blue" with the word 'Blue' coloured and on the next line as expected.
However if I try this with git output, such as
var=$(git status) echo $var
It loses all the newlines and colouring.
How can I capture the output of a git command and print it later on, while preserving formatting and colouring in bash?