The short answer is to do
printf "%s\n" $GRAPH
When you capture the output from a command into a shell variable with
`…`, the last newline is stripped, and
printf "%s" … (unlike
echo) does not append a newline by default. So, when you say
printf "%s" $GRAPH, you are getting the next shell prompt on the same line as your
Secondly, I advise you to change that to
printf "%s\n" "$GRAPH"
to protect against certain funny characters showing up in
$GRAPH –– and you are clearly getting funny characters.
Thirdly, you say, “the
% appears to be inside a black bar”. That appears to be inverse video, in which foreground and background colors are reversed. That may be caused by one or some of the characters in
$GRAPH. If everything else you do until the end of time is in inverse video, even after you’ve done the above two steps, try
printf "%s\n" "$GRAPH"; tput sgr0
tput exercises terminal-specific functionality; in many cases by writing a string.
sgr0 is the short name for the
exit_attribute_mode capability, which sets foreground and background colors back to normal (and turns off underline, blink, and whatever other display attributes your terminal supports).