1

I want to move the bash cursor in an echo command on a specific column, but without changing the line. What I have so far is:

this.echo('NONE found on ' + accountName + '(' + accountPos + ')' + '\033[30f !!!');

I want the 30 to be the column number, but the line to stay the same, but for a reason or another, the above just thinks my line number is 0, hence it resets the line to that value.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Vlad Balanescu
  • 664
  • 5
  • 27
  • 1
    Possible duplicate of [Bash text absolute positioning](https://stackoverflow.com/questions/20381937/bash-text-absolute-positioning) – tripleee Sep 13 '19 at 18:06

3 Answers3

2

Found the answer to my own question, by moving the cursor at the beginning of line and then move it forward by 30 columns, as in this example:

\033[50D\033[30C My Text Goes Here
Vlad Balanescu
  • 664
  • 5
  • 27
-2

There's more than one way, but the simplest would be HPA (refer to XTerm Control Sequences):

CSI Pm `  Character Position Absolute  [column] (default = [row,1])
          (HPA).

For example

printf '\033[30`%s\n' "My Text Goes Here"

Further reading: ECMA-48: Control Functions for Coded Character Sets

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
-2

Below are instructions on how to move your cursor within a bash script or determine the current location of your cursor within a bash script ( or any text file ) using the vi text editor from a bash shell ( i.e. terminal ).

First, you will want to open the bash script ( or any text file ) using the vi editor.

vi bashscript.sh

If you want to move the cursor to line 10 and column 2 within a bash script using the vi editor run the below command ( note you type ':' to enter a command ).

:cal cursor(10, 2)

If you want to see your current row and column within a bash script using the vi editor run the below command.

:echo "Row = " line('.') ", Col = " virtcol('.')
Shane
  • 1
  • 2