I am encountering strange behaviour when trying to switch on and off background colors in terminal output:
#!/bin/sh printf "\e[48;5;203m" printf "AAA\n" printf "\e[0m" printf "BBB\n" printf "CCC\n" I want AAA to be printed with red background, then switch off the background color, and print the next lines. However, this is how the output looks like:
UPDATE
OK, I tried from a new terminal, and there it works as expected. But I still have the old terminal window open, where I get the output as shown. What is happening there? Is there some "garbage" left in the terminal, that is causing this?
I did reset in the old terminal window, and the output is now correct.

xterm(work as intended)printf "\e[48;5;203mAAA\e[0m\nBBB\nCCC\n"works as expected and doesn't have the issues you mention.printf "AAA\n"there is actually output coming from a command. I used simplified code for demonstration.