The short answer is to do
printf "%s\n" $GRAPH
When you capture the output from a command into a shell variable with $(…)
or `…`
, 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 printf
output.
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).
A couple of comments. (1) What is
spark
? I’ve never heard of it, and I didn’t find any reference to it in Super User (in a quick search). The more information you can give about your problem and your situation (within reason), the easier it is for us to help you. (2) One of the cardinal rules of testing/debugging/troubleshooting is to change only one thing at a time. Why did you use “25” withprintf
and “76” without? Do the first four lines of your question (… “76” …) have anything to do with the rest of the question? – Scott – 2013-02-20T18:26:44.257