The command I had seen was tput
. One could use it ± as in my question:
echo -n "$(tput home)"
But of course that particular example is redundant; it's wasteful to run the stdout of tput
into an argument that echo
will write to its own stdout. It might make a little more sense if you needed to generate a string of echo -n "$(tput thing1)some text$(tput thing2)other text
— but as @icarus points out in a comment below, this would lose any timing tricks that tput
knows about.
So the utility would best be called directly whenever practical:
tput clear
tput blink
echo "DANGER WILL ROBINSON"
tput bel
sleep 5
reset # NOTE: this might be symlinked to tput also!
It is not a core/built-in tool, but is provided as part of ncurses and should be pretty widely available as a result. I found a nice intro/overview that gives some background, showing related commands as well. And this gist contains a handy listing of all the named "capabilities" that could be output.
echo -n "$(tput home)"
, but just usetput home
. Whilst uncommon these days tput can be outputting delays which are lost. It is also less efficient to start up a shell to capture the output of a command just to then output it again. – icarus Jan 16 '20 at 00:59reset
comman — although on my daily system (macOS) it is symlinked totset
rather thantput
. See https://unix.stackexchange.com/questions/335648/why-does-the-reset-command-include-a-delay (via https://unix.stackexchange.com/questions/546918/any-reason-to-not-alias-reset-tput-reset-in-bashrc) for more discussion regarding that side topic. – natevw Jan 16 '20 at 18:21