How to get the cursor position in bash ?
Posted
by Julien Nicoulaud
on Stack Overflow
See other posts from Stack Overflow
or by Julien Nicoulaud
Published on 2010-04-04T16:16:58Z
Indexed on
2010/04/04
16:23 UTC
Read the original article
Hit count: 421
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 following way:
# Query the cursor position
echo -en '\033[6n'
# Read it to a variable
read -d R CURCOL
# Extract the column from the variable
CURCOL="${CURCOL##*;}"
# We have the column in the variable
echo $CURCOL
Unfortunately, this prints characters to the standard output and I want to do it silently. Besides, this is not very portable...
Is there a pure-bash way to achieve this ?
© Stack Overflow or respective owner