在bash脚本中,我想在变量中获取游标列.看起来使用ANSI转义码{ESC}[6n是获取它的唯一方法,例如以下方式:
# 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
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会将字符打印到标准输出,我想静静地进行.此外,这不是很便携......
是否有一种纯粹的bash方式来实现这一目标?