In a contrived example, if I have the following:
sup="$(printf "\e[s" > /dev/tty; printf "one" > /dev/tty; printf "\e[u\e[Jtwo" > /dev/tty)"
The output will successfully erase one
leaving only:
two
However, if I use echo "one"
to print a newline with it:
sup="$(printf "\e[s" > /dev/tty; echo "one" > /dev/tty; printf "\e[u\e[Jtwo" > /dev/tty)"
Then the output is:
one
two
Why would the newline break the cursor handling? And how could I work around it?
A more comprehensive example would be:
sup="$(printf "\e[s" > /dev/tty; for (( i=0; i<5; i++)); do echo -e "a random number is:\n$RANDOM" > /dev/tty; sleep 1; printf "\e[u\e[J" > /dev/tty; done; echo 'result')"
echo "sup=$sup" # sup=result