【发布时间】:2011-02-04 05:24:57
【问题描述】:
在 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
不幸的是,这会将字符打印到标准输出,我想默默地做。此外,这不是很便携...
有没有一种纯 bash 的方式来实现这一点?
【问题讨论】:
标签: bash text-cursor