The answer from ks1322 helped me to identify the issue while using docker-compose exec
:
If you omit the -T
flag, docker-compose exec
add a special character that break output, we see b
instead of 1b
:
$ test=$(/usr/local/bin/docker-compose exec db bash -c "echo 1")
$ echo "${test}b"
b
echo "${test}" | cat -vte
1^M$
With -T
flag, docker-compose exec
works as expected:
$ test=$(/usr/local/bin/docker-compose exec -T db bash -c "echo 1")
$ echo "${test}b"
1b