Please consider following snippet which should enter kubernetes mysql pod container and should initialise BAR variable to a list of mysql databases.
kubectl -n somens exec -i mysql-69df7d4c77-hxtng bash <<EOF
echo Hello;
BAR=$(echo "show databases" | mysql -u root -pwhatever)
echo "BAR=\$BAR"
EOF
If I change line
BAR=$(echo "show databases" | mysql -u root -pwhatever)
to
echo "show databases" | mysql -u root -pwhatever
I will get printed a list of databases while executing entire snippet.
When I run the original, I get empty BAR variable.
Now I know that BAR can be initialised and I am printing it correctly as I tried to set it to test string and print out.
Currently I have a script which runs:
BAR=$(echo "show databases" | mysql -u root -pwhatever)
outside of container and not inside "heredoc", and it initialises the variable properly.
How can I initialise bar correctly using "heredoc"? I apologise for specificity of the example, would not want to lose details converting it to what I believe is similar and not what it actually is(poor dev here).