I am trying to create a small tutorial-like script to refresh my bash skills.
I have defined a variable DISPLAY_TEXT
that has some text and a set of escape characters and colors like so:
DISPLAY_TEXT=${WHITE}\n\t \t ==== $HEADER ====\n\n${NOCOL}"
WHITE
and NOCOL
defined with their appropriate ANSI escape codes.
Then, using a simple pipe with echo
, I redirect the value of a variable DISPLAY_TEXT
to less
with echo -e $DISPLAY_TEXT | less
.
The arguments I have set for less are as so:
less --prompt=["Navigate using arrows (or touchpad). Enter 'q' to exit"] -r
With -r
to output raw characters.
The program gets executed fine and the output is as expected with colors showing (until I scroll down and up again). The main odd behaviour is displayed in the next picture.
Is there something I am not understanding with basic redirection, less or bash in general? This behaviour isn't limiting my script but it is something that I'm interested in understanding.