How to get the cursor position in bash?

后端 未结 6 2213
遥遥无期
遥遥无期 2020-11-27 02:46

In a bash script, I want to get the cursor column in a variable. It looks like using the ANSI escape code {ESC}[6n is the only way to get it, for example the fo

6条回答
  •  情歌与酒
    2020-11-27 03:31

    You could tell read to work silently with the -s flag:

    echo -en "\E[6n"
    read -sdR CURPOS
    CURPOS=${CURPOS#*[}
    

    And then CURPOS is equal to something like 21;3.

提交回复
热议问题