-2

I came across with code like this:

function cursorBack() {
   echo -en "\033[$1D"
}
...
tput civis 
...
cursorBack 1

What does the number do?

Lunartist
  • 375
  • 2
  • 13
  • 1
    What does this letter do?, I ask you. Can you find out to which letter I refer? – Quasímodo Apr 06 '21 at 01:17
  • 1
    Related: [How to pass parameters to function in a bash script?](https://unix.stackexchange.com/a/298717/65304) – steeldriver Apr 06 '21 at 01:18
  • @Quasímodo what letter? I support your fight against the malicious cookie banner with embedded google code – john doe Apr 06 '21 at 01:19
  • @johndoe My point exactly. There are multiple numbers in the function, how can we know which one the asker is asking about? Thanks for the support by the way (I really do not know about Google though). – Quasímodo Apr 06 '21 at 01:21
  • @Quasímodo Which letter? I'm not your mom so I can't read your mind. Can you find out which mom I refer? – Lunartist Apr 06 '21 at 01:34

1 Answers1

5

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.

9769953
  • 111
  • 6