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 ?