I came across with code like this:
function cursorBack() {
echo -en "\033[$1D"
}
...
tput civis
...
cursorBack 1
What does the number do?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI came across with code like this:
function cursorBack() {
echo -en "\033[$1D"
}
...
tput civis
...
cursorBack 1
What does the number do?
It's an argument to the function: note the $1
part in the echo string: that is the first argument being used by the bash function. Try running the function with varying arguments, e.g. cursorBack 5
, or even cursorBack foo
, to see what happens.
Note that the first part of the echo command is an ANSI escape, followed by the function argument (a number), followed by the letter D
. That letter means back (think delete, without removing the character), so it moves it n positions back (1 position in your example).
Logically, using foo
as an argument will thus not do what it's supposed to do: the arguments in this specific case should only be (integer) numbers.